Dynamically import a component only when it’s needed, enabling bundle splitting and faster initial load.
const SomeComponent = React.lazy(() => import('./SomeComponent'));
React.lazy() accepts a function that returns a dynamic import()<Suspense fallback={...}> boundaryimport { Suspense, lazy } from 'react';
const Chart = lazy(() => import('./Chart'));
function Dashboard() {
return (
<Suspense fallback={<p>Loading chart...</p>}>
<Chart />
</Suspense>
);
}
| Rule / Limitation | Explanation |
|---|---|
❗ Must wrap in <Suspense> |
Required to handle loading state during import |
| ❗ Works only with default exports | Named exports not supported |
| ✅ Supported in Client Components only | Not supported in Server Components (RSC) |
lazy() only for component-level code splittingReact Router)fallback UI (skeleton, spinner, etc.)