React Suspense simplifies async data handling. Here's how to use it for data fetching.
Basic Suspense#
The use Hook (React 19+)#
Resource Pattern#
Error Boundaries#
Nested Suspense#
Streaming with Suspense#
React Query with Suspense#
SWR with Suspense#
Transitions#
Preloading Data#
Best Practices#
Loading States:
✓ Use skeleton components
✓ Place Suspense boundaries strategically
✓ Show meaningful loading states
✓ Avoid layout shift
Error Handling:
✓ Wrap Suspense with ErrorBoundary
✓ Provide retry mechanisms
✓ Show helpful error messages
✓ Log errors for debugging
Performance:
✓ Preload data on hover
✓ Use transitions for tab changes
✓ Cache data appropriately
✓ Stream server components
Conclusion#
React Suspense transforms async data handling with declarative loading states. Use the use hook for simple cases, React Query or SWR for advanced caching, and ErrorBoundary for error handling. Place Suspense boundaries strategically for optimal user experience.