Suspense
Suspense lets components suspend rendering while waiting for asynchronous operations (code splitting, data fetching, streaming).
Mental Model
"The Theater Curtain: The stage crew arranges the set behind a decorative curtain (fallback) before revealing the live scene."
Interactive Engine Walkthrough
Reference Code Snippet
1<Suspense fallback={<Skeleton />}>
2 <DataGrid />
3 <Comments />
4</Suspense>
5
6// If ANY child is "suspending",
7// the fallback will be shown.- 01.Suspense coordinates async loading states declaratively without manual if (isLoading) boilerplate.
- 02.Supports nested fallbacks: granular loaders display as individual components resolve.
- 03.In React 19, the use() hook allows unwrapping promises directly inside components wrapped in Suspense.
01. Handling Uncertainty
`Suspense` is a component that lets you "wait" for some code to load and declaratively specify a loading state. Unlike manual loading flags (`if (loading) return ...`), Suspense allows you to coordinate multiple asynchronous components at the tree level.
Tree State
02. Beyond Code Splitting
In modern React frameworks (like Next.js), Suspense is also used for **Data Fetching**. A component can "suspend" while waiting for an API response. React will catch this "suspension" and show the nearest fallback until the data is resolved and the component can finish its work.
Architectural Advice
"Think of Suspense as a **Boundary of Order**. It prevents the 'Pop-in' effect where UI elements jump around as different data loads at different speeds. It keeps the UI stable until the content is ready."