Last active
January 24, 2025 07:55
-
-
Save harshq/c47113c2f6f3583a123f2a2e8a5a4dc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Suspense } from 'react' | |
import UseApiClientComponent from './use-api-client-component'; | |
import ErrorBoundary from './ErrorBoundry'; | |
import ExampleSection from '../shared/ExampleSection'; | |
const UseApiServerComponent: React.FC = () => { | |
// promise is created on the server component | |
const promise = fetch(`https://jsonplaceholder.typicode.com/posts/1`, { cache: 'no-store' }).then(res => res.json()) | |
return ( | |
<ExampleSection> | |
{/* | |
we have an suspense around client component. | |
This makes sure, we see a fallback UI until | |
the promise is resolved. | |
*/} | |
<ErrorBoundary> | |
<Suspense fallback={<p>Streaming data...</p>}> | |
<UseApiClientComponent data={promise} /> | |
</Suspense> | |
</ErrorBoundary> | |
</ExampleSection> | |
); | |
} | |
export default UseApiServerComponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment