Consider this Next.js component using Suspense and streaming. What will the user see first when this component renders?
import React, { Suspense } from 'react'; function SlowComponent() { const data = new Promise(resolve => setTimeout(() => resolve('Loaded Data'), 3000)); const text = React.use(data); return <div>{text}</div>; } export default function Page() { return ( <Suspense fallback={<div>Loading...</div>}> <SlowComponent /> </Suspense> ); }
Think about what Suspense does when waiting for data.
The Suspense component shows the fallback content ('Loading...') immediately while waiting for the promise to resolve. After 3 seconds, the resolved data replaces the fallback.
Given this Next.js streaming Suspense example, what is the final rendered HTML content?
import React, { Suspense } from 'react'; function Data() { const promise = new Promise(resolve => setTimeout(() => resolve('Hello from server'), 2000)); const message = React.use(promise); return <p>{message}</p>; } export default function Page() { return ( <Suspense fallback={<p>Loading message...</p>}> <Data /> </Suspense> ); }
Remember how Suspense fallback works with async data.
The fallback
Loading message...
shows first. After 2 seconds, the promise resolves and theHello from server
replaces the fallback.Examine this Next.js component using Suspense and streaming. Why does it cause a runtime error?
import React, { Suspense } from 'react'; function BrokenComponent() { const data = fetch('/api/data').then(res => res.json()); const result = React.use(data); return <div>{result.value}</div>; } export default function Page() { return ( <Suspense fallback={<div>Loading...</div>}> <BrokenComponent /> </Suspense> ); }
Consider how React.use works with promises and what it expects.
React.use expects a special kind of promise (a React Suspense resource). A raw fetch promise does not work directly and causes a runtime error.
Choose the correct statement about how streaming with Suspense works in Next.js.
Think about how Suspense helps with loading states and partial rendering.
Streaming with Suspense lets Next.js send HTML chunks to the browser as soon as they are ready, showing fallback UI for parts still loading.
Identify the correct code snippet that uses streaming Suspense with an async server component in Next.js 14+.
Remember async components must be awaited and Suspense fallback is required for streaming.
Option C correctly defines an async component that awaits data, wrapped in Suspense with a fallback. Option C lacks Suspense, C misuses React.use with raw promise, B does not await data.