React Suspense lets you declaratively handle loading states for async operations. Here's how to use it.
Basic Suspense
Nested Suspense
Loading Fallbacks
Error Boundaries with Suspense
Data Fetching with Suspense
SuspenseList (Experimental)
Transitions with Suspense
useDeferredValue
Route-based Code Splitting
Best Practices
Fallback Design:
✓ Match fallback to content shape
✓ Use skeleton screens for better UX
✓ Keep fallbacks lightweight
✓ Avoid layout shifts
Boundaries:
✓ Place near async content
✓ Use nested Suspense for granularity
✓ Combine with Error Boundaries
✓ Consider user experience flow
Performance:
✓ Preload critical paths
✓ Use transitions for navigation
✓ Avoid waterfall loading
✓ Cache fetched data
Avoid:
✗ Suspense boundary too high
✗ Missing error handling
✗ Flash of loading states
✗ Over-splitting code
Conclusion
React Suspense provides a declarative way to handle loading states. Use it with lazy loading for code splitting, combine with Error Boundaries for robust error handling, and leverage transitions for smooth navigation. Design fallbacks that match your content structure to minimize layout shifts.