Suspense lets you display a fallback UI while its children are loading. It enables components to “suspend” rendering while waiting for asynchronous data to load.
Type
Suspense is represented by the symbol Symbol.for('react.suspense') (the value of REACT_SUSPENSE_TYPE in React’s source).
Props
ReactNode
required
The actual UI you intend to render. If
children suspends while rendering, the Suspense boundary will switch to rendering the fallback.ReactNode
required
An alternate UI to render in place of the actual UI if it hasn’t finished loading. Any valid React node is accepted, though in practice, a fallback is a lightweight placeholder view such as a loading spinner or skeleton.The fallback will automatically be replaced by the children when the data is ready.
Usage
Basic Example
Multiple Suspense Boundaries
You can have multiple Suspense boundaries at different levels:- Each section can suspend independently
- Inner Suspense boundaries catch suspensions first
- If multiple children suspend, only the nearest Suspense boundary’s fallback is shown
Nested Suspense
Suspense boundaries can be nested to create cascading loading states:What Can Suspend?
Suspense works with:1. React.lazy() - Code Splitting
2. Data Fetching with Frameworks
Frameworks like Relay, Next.js, and Remix support Suspense for data fetching:3. React 19+ use() Hook
4. Server Components (React Server Components)
Showing Content as it Loads
Use multiple Suspense boundaries to show content progressively:- Header and Footer show immediately
- MainSkeleton shows while MainContent loads
- MainContent appears when ready
- CommentsSkeleton shows while Comments load
- Comments appear when ready
Error Boundaries
Suspense works together with Error Boundaries to handle errors during loading:- If
DataComponentsuspends →<Loading />is shown - If
DataComponentthrows an error →<ErrorPage />is shown - If
DataComponentsucceeds → component renders normally
Combined Pattern
Transitions and Suspense
Use transitions to avoid hiding already visible content:- The current tab stays visible while the new tab loads
- A spinner indicates loading is happening
- Better user experience than showing fallback immediately
Preventing Unwanted Fallbacks
Problem: Fallback Flashing
If data loads quickly, showing a loading spinner can create a jarring flash:Solution: Use Transitions
- The old content stays visible during refresh
- The button shows loading state instead
- Fallback only shows for initial load, not refreshes
Use Cases
Code Splitting
Data Fetching
Parallel Loading
Waterfall Prevention
Start requests before rendering:Best Practices
1. Use Meaningful Fallbacks
2. Place Boundaries Strategically
3. Handle Errors
4. Use Transitions for Updates
Common Pitfalls
Server-Side Rendering:Suspense works with SSR to stream HTML to the client. Components that suspend are rendered on the server and sent when ready, allowing the browser to show content progressively.