Course contentsShow
← React
Lesson 1341 of 2,39634. Suspense FundamentalsFree lesson

Nested Suspense Boundaries

Inner Suspense boundaries can show localized loading states while outer boundaries handle broader transitions.

Nested Suspense Boundaries

What you'll learn: How to use multiple Suspense boundaries at different levels to show localized loading states instead of blocking your entire UI.

The Problem with Single Boundaries

When you wrap your entire app in one Suspense boundary, everything shows the same fallback whenever anything loads. That's like turning off all the lights in a house just because you need to change one bulb.

Multiple Boundaries for Granular Loading

You can nest Suspense boundaries at different levels of your component tree. Inner boundaries catch loading states for specific features, while outer boundaries handle broader transitions:

<Suspense fallback={<PageSkeleton />}>
  <Header />
  
  <Suspense fallback={<SidebarSkeleton />}>
    <Sidebar />
  </Suspense>
  
  <Suspense fallback={<ContentSpinner />}>
    <MainContent />
  </Suspense>
</Suspense>

How It Works

When <Sidebar> suspends (isn't ready), only its nearest boundary shows the fallback—<SidebarSkeleton />. The header and main content keep rendering normally. The outer boundary only activates if the entire page suspends during initial load.

This creates a better user experience: users see partial content immediately, with loading indicators only where data is still pending.

Real-World Analogy

Think of a restaurant where different sections can be "loading" independently: the kitchen preparing your entrée, the bar making drinks, and the dessert station. You don't want the entire restaurant to close just because desserts aren't ready yet—each section shows its own "in progress" state.

Key Takeaway: Nested Suspense boundaries allow you to show localized, component-specific loading states rather than blocking your entire UI, creating smoother and more informative loading experiences.