Skip to main content

React Suspense Integration

Learn how to use React Suspense with React Router for declarative loading states.

Overview

React Router integrates seamlessly with React’s Suspense API, allowing you to show fallback UIs while data is loading. This provides a better user experience with declarative loading states.

Basic Suspense Usage

Wrap components in Suspense boundaries:

Defer Data Loading

Use defer to stream non-critical data:

Error Boundaries with Suspense

Handle errors in deferred data:

Parallel Loading

Load multiple resources in parallel:

Nested Suspense Boundaries

Create granular loading states:

Skeleton Screens

Create effective loading skeletons:
Style skeletons:

Progressive Enhancement

Improve perceived performance:

Timeout Fallbacks

Show fallback after a delay:

Best Practices

  1. Defer non-critical data - Load important content first
  2. Use meaningful skeletons - Match the shape of actual content
  3. Keep fallbacks simple - Avoid complex loading states
  4. Handle errors gracefully - Provide retry mechanisms
  5. Avoid layout shift - Reserve space for loading content
  6. Consider mobile - Simpler skeletons on slower connections
  7. Test loading states - Throttle network to see fallbacks
  8. Use suspense boundaries wisely - Don’t wrap everything in one boundary