Home / Learn React / Suspense and lazy Loading
Suspense and lazy Loading
<Suspense> shows a fallback (like a spinner) while something below it is not ready: a lazy component, a data promise or a loading route.
Theory in plain words
What it is
Suspense is a boundary. When a component inside it "suspends" (it is waiting), React shows the fallback for that boundary instead. React.lazy loads a component's code on demand.
Why we use it
Without it you write if (loading) return ... in every component. Suspense lets loading states be placed once, near the layout, and it supports code splitting to make the first page load smaller.
How it works
The nearest Suspense above the waiting component takes over and shows its fallback. You can nest boundaries to show parts of the page as soon as they are ready.
Where it is used
- Code splitting by route or by big component
- Data fetching with
use, TanStack Query or frameworks - Streaming server rendering
lazy components
import { lazy, Suspense } from "react";
const Settings = lazy(() => import("./Settings.jsx")); // separate file, separate JS chunk
<Suspense fallback={<Spinner />}>
<Settings />
</Suspense>Two boundaries load independently
Quick quiz
1. What does the fallback prop of Suspense hold?
For example a spinner or a skeleton.
2. What does React.lazy help with?
It enables code splitting.
3. Two separate Suspense boundaries...
Each shows its own fallback.
Common questions
What does the fallback prop of Suspense hold?
What to show while waiting. For example a spinner or a skeleton.
What does React.lazy help with?
Loading a component code only when needed. It enables code splitting.