Skip to content

Instantly share code, notes, and snippets.

@harshq
Last active January 24, 2025 07:55
Show Gist options
  • Save harshq/c47113c2f6f3583a123f2a2e8a5a4dc5 to your computer and use it in GitHub Desktop.
Save harshq/c47113c2f6f3583a123f2a2e8a5a4dc5 to your computer and use it in GitHub Desktop.
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