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
From packages/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
Suspense for data fetching is still experimental. Use frameworks like Next.js, Remix, or libraries that support Suspense-enabled data fetching.
SuspenseList (Experimental)
From packages/react/src/ReactClient.js:116:
Coordinate the loading order of multiple Suspense boundaries:
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:
Never manually throw promises for Suspense. Use libraries that properly integrate with Suspense or wait for official data fetching Suspense support.
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