Capítulo 87 de 116
lazy(load) code-splits a component — instead of bundling it eagerly, its code chunk downloads only when it's first about to render, causing the nearest Suspense boundary to show its fallback while the download is in flight.
const SomeComponent = lazy(() => import('./SomeComponent.js')) — load is a function returning a promise that resolves to a module with a default export of the component.Suspense boundary: a lazy component suspends (Ch 70) while its chunk is loading — without a Suspense ancestor to catch that, there's no fallback to show during the download.import() call is only made when first needed: React calls load() the first time it actually needs to render that component — not eagerly at module-evaluation time — which is what makes this a genuine code-splitting boundary rather than just an async wrapper.const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
<Suspense fallback={<Spinner />}>
<MarkdownPreview />
</Suspense>
MarkdownPreview only downloads once this JSX actually attempts to render, with Spinner showing meanwhile.lazy-loaded component in a Suspense boundary — without one, there's nothing to show while its code downloads.lazy(() => import(...)), so place it around genuinely separable, non-critical-path pieces of the UI.