Code splitting with lazy
A component's JavaScript module is loaded on demand and may suspend on first render.
React 19+ · Component
Suspense displays a fallback while descendant UI is not ready, then reveals that UI when it can render. Use boundaries to define loading regions and coordinate progressive or streamed content.
Suspense creates a boundary around child UI that may not be ready during rendering. When a child suspends, React temporarily renders the fallback; once the child is ready, React replaces the fallback with the child content. Boundaries can also coordinate progressive loading and server-rendered streaming.
<Suspense fallback={fallback}>{children}</Suspense>| Name | Type | Description |
|---|---|---|
children | ReactNode | The React nodes to render when ready. If they suspend during rendering, the boundary renders fallback instead. |
fallback | ReactNode | The alternate React node shown while children have not finished loading. |
A React element that renders children when ready and fallback while children are suspended.
import { Suspense, lazy } from 'react';
const Preview = lazy(() => import('./Preview.js'));
export default function App() {
return (
<Suspense fallback={<p>Loading preview…</p>}>
<Preview />
</Suspense>
);
}A lazy component suspends while its module loads, so the boundary displays a lightweight fallback and then renders the loaded component.
A component's JavaScript module is loaded on demand and may suspend on first render.
Different parts of a page become ready at different times and should reveal in coordinated groups.
Server-rendered content can be sent in independently renderable regions.
Suspense renders its fallback when a descendant suspends while rendering, then switches back to the children when they are ready. A suspended boundary can wait for lazy component code, a Promise read with use, or certain stylesheet loads.
Follow-up: How would you avoid hiding content that is already visible during navigation? Wrap the non-urgent update in startTransition so React can delay the fallback replacement.
The fallback is an alternate React node rendered in place of unfinished children. It should usually be lightweight, such as a spinner or skeleton, and it must not itself suspend unless an enclosing boundary can handle that suspension.
Follow-up: What happens if the fallback suspends? React activates the closest parent Suspense boundary.
Suspense boundaries let an application choose which regions reveal together and which progressively reveal through nested loading states. During server rendering, React includes the fallback in the HTML and later replaces it in the browser with the saved content.
Follow-up: How can a server-rendered page reveal independent regions sooner? Place separate Suspense boundaries around regions that can load independently, allowing their content to stream separately.
lazyusestartTransitionServer Components