Overview
Suspense is a React component that lets you specify a loading state while waiting for some asynchronous operation to complete. It works with lazy-loaded components, data fetching, and other async operations.Basic Usage
Suspense API
Frompackages/react/src/ReactClient.js:105:
Props
- fallback: The content to display while children are loading (required)
- children: The components that may suspend
With Code Splitting
Nested Suspense Boundaries
Use multiple Suspense boundaries for granular loading states:Data Fetching with Suspense
SuspenseList (Experimental)
Frompackages/react/src/ReactClient.js:116:
SuspenseList Props
- revealOrder:
"forwards"|"backwards"|"together"- Controls display order - tail:
"collapsed"|"hidden"- Controls fallback display
Loading States Best Practices
Skeleton Screens
Progressive Enhancement
Error Handling with Suspense
Combine Suspense with Error Boundaries:Suspense with Transitions
Combine Suspense with transitions to avoid hiding existing content:Practical Examples
Image Lazy Loading
Tabbed Content
Modal with Lazy Content
Timeout and Retry
Suspense Internal Behavior
Suspense works by catching thrown promises:Best Practices
- Use meaningful fallbacks: Show skeleton screens instead of spinners when possible
- Multiple boundaries: Use multiple Suspense boundaries for better UX
- Combine with error boundaries: Always handle errors alongside loading states
- Progressive enhancement: Load critical content first
- Test loading states: Explicitly test that loading states appear correctly
- Avoid waterfalls: Structure data dependencies to prevent loading waterfalls
- Use transitions: Combine with useTransition for better perceived performance
Common Patterns
Waterfall Prevention
See Also
- Code Splitting - Lazy loading components
- Concurrent Features - Transitions and deferred values
- Error Boundaries - Handling errors