Suspense Boundary Required for lazy Components
What you'll learn: Why every React.lazy() component must be wrapped in a <Suspense> boundary, and what breaks if you skip it.
When you use React.lazy() to dynamically load a component, React needs somewhere to show a fallback UI while the code downloads. That "somewhere" is a <Suspense> boundary. If you forget to wrap a lazy component in Suspense, React will throw an error.
Why the Requirement Exists
Think of it like a safety net below a trapeze artist. When a lazy component "suspends" (throws a promise while loading), React looks up the component tree for the nearest <Suspense> boundary to catch it. Without that boundary, the promise has nowhere to go—it bubbles all the way to the root and crashes your app.
React requires this boundary because lazy components don't immediately return JSX. During the initial render, they suspend while import() fetches the code. React needs explicit instructions (the fallback prop) for what to display during that wait.
What Happens If You Forget
// ❌ This will throw an error
const LazyComponent = React.lazy(() => import('./Heavy'));
function App() {
return <LazyComponent />; // Error: A component suspended while rendering...
}
React will tell you: "A component suspended while responding to synchronous input... Wrap the component tree with <Suspense>"
The Fix
// ✅ Works correctly
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
Now React knows to show "Loading..." while the code downloads.
Key Takeaway: Every React.lazy() component must have a <Suspense> boundary above it in the tree—without one, React throws an error because it has no fallback UI to display during code loading.