Complete the code to enable streaming in a Next.js Server Component.
import { Suspense } from 'react'; export default function Page() { return ( <[1] fallback={<div>Loading...</div>}> <div>Hello, streaming!</div> </[1]> ); }
Wrapping content in <Suspense fallback={...}> enables streaming in Next.js Server Components, allowing the fallback to render first.
Complete the code to use React's Suspense for partial rendering in Next.js.
import { Suspense } from 'react'; export default function Page() { return ( <Suspense fallback={<div>Loading...</div>}> <[1] /> </Suspense> ); }
Server components can be streamed and wrapped in Suspense for partial rendering.
Fix the error in the code to enable streaming with async Server Components.
export default async function Page() {
const data = [1]fetchData();
return <div>{data.message}</div>;
}Await is needed to resolve the promise before rendering the message.
Fill both blanks to create a streaming layout with a loading fallback.
import { Suspense } from 'react'; export default function Layout({ children }) { return ( <div> <Suspense fallback={<[1]>Loading...</[2]>}> {children} </Suspense> </div> ); }
Using <main> for the fallback is semantic and accessible.
Fill all three blanks to implement streaming with a suspense boundary and async data fetch.
import { Suspense } from 'react'; async function fetchUser() { const res = await fetch('/api/user'); return res.json(); } async function UserContent() { const user = await fetchUser(); return ( <h1>Hello, [3]</h1> ); } export default function Page() { return ( <Suspense fallback={<[1]>Loading user...</[2]>}> <UserContent /> </Suspense> ); }
Use a <div> for fallback, and display user.name from fetched data.