Dynamically import a component only when it’s needed, enabling bundle splitting and faster initial load.

Basic Syntax

const SomeComponent = React.lazy(() => import('./SomeComponent'));

Example

import { Suspense, lazy } from 'react';

const Chart = lazy(() => import('./Chart'));

function Dashboard() {
  return (
    <Suspense fallback={<p>Loading chart...</p>}>
      <Chart />
    </Suspense>
  );
}

Use Cases

Important Notes

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)

Best Practices

Lazy + Named Exports Workaround