React.lazy
The React function that defines a component whose code is loaded with a dynamic import the first time it renders.
In more detail
lazy(() => import("./Settings")) returns a component that suspends while its code downloads, so it must be rendered inside a Suspense boundary. Declare lazy components at the top level of a module, never inside another component, or their state resets every render.
Example
const SettingsModal = lazy(() => import("./SettingsModal"));Related terms
- code splitting — Dividing an app JavaScript into several files that load only when needed, instead of one big file up front.
- dynamic import — The import() expression that loads a JavaScript module at run time and returns a promise for it.
- Suspense — A React component that shows a fallback, such as a spinner or skeleton, while components inside it are waiting for something to load.
Taught in
- Suspense Architecture: Promises, Fallbacks, And Co-ordination — React 19 & Modern Component Architecture
- Code-Splitting with React.lazy: Dynamic Imports And Chunks — React 19 & Modern Component Architecture