React Suspense, made tangible. A component "suspends" by reading a promise with
use(); the nearest<Suspense>shows a fallback until it resolves. Watch parallel boundaries load independently,useTransitionskip the fallback flash, andReact.lazycode-split a component into its own chunk.
▶ Live demo · What's inside · Run locally
Suspense sounds abstract — "a component suspends and the boundary shows a fallback" — until you watch it happen. This has four live boundaries you can trigger, each with the code beside it, so the model (and the newer use() hook) clicks.
- Suspense basics — a component reads a promise with
use(); until it resolves it suspends, and the nearest<Suspense>shows a skeleton. Reload → it suspends again. - Parallel boundaries — two independent
<Suspense>regions resolve on their own, so the fast one shows content while the slow one is still loading. No all-or-nothing wait. useTransition— no fallback flash — a plain reload drops back to the skeleton; wrapping the update instartTransitionkeeps the old content on screen (isPending) while the new data loads. Side-by-side buttons to feel the difference.React.lazy— code splitting — the panel lives in its own JS chunk (you can seeLazyPanel-*.jsin the build) that isn't downloaded until you ask for it; Suspense covers the network wait.
When a component reads a not-yet-ready promise (via use(), or historically by throwing the promise), React suspends that subtree and walks up to the nearest <Suspense> to render its fallback. When the promise resolves, React retries the render and swaps the real content in. That's the whole model — and it composes: boundaries nest, siblings load in parallel, and useTransition lets you keep the old UI visible instead of falling back while new data streams in.
npm install
npm run dev
npm run build # note the separate LazyPanel chunk in the outputIdeas: <Suspense> + error boundary combo, streaming SSR note, useDeferredValue vs useTransition, a waterfall-vs-parallel data-fetching comparison. PRs welcome.
If this made Suspense click, a ⭐ helps others find it.
MIT © dev48v