Suspense wraps part of the component tree and shows its fallback prop instead of that tree's actual content whenever something inside has suspended, signaled a not-ready-yet state, most classically a React.lazy()-loaded component whose code chunk is still downloading. Once the suspended work actually completes, Suspense automatically swaps the fallback out for the real content. A single Suspense boundary can wrap multiple lazy components at once, showing one shared fallback until all of them are ready, and multiple Suspense boundaries can also be nested to show more granular, localized loading states for different parts of a page independently.
1Understanding Handling Loading with Suspense
Suspense wraps part of the component tree and shows its fallback prop instead of that tree's actual content whenever something inside has suspended, signaled a not-ready-yet state, most classically a React.lazy()-loaded component whose code chunk is still downloading. Once the suspended work actually completes, Suspense automatically swaps the fallback out for the real content. A single Suspense boundary can wrap multiple lazy components at once, showing one shared fallback until all of them are ready, and multiple Suspense boundaries can also be nested to show more granular, localized loading states for different parts of a page independently.
Wrap multiple related lazy components in one single shared Suspense boundary when they should all appear together at once, avoiding a jarring, staggered sequence of separate loading indicators popping in one after another as each component individually finishes loading.
import React, { Suspense } from 'react';
const Chart = React.lazy(() => import('./Chart'));
const Table = React.lazy(() => import('./Table'));
function Dashboard() {
return (
<Suspense fallback={<p>Loading dashboard...</p>}>
<Chart />
<Table />
</Suspense>
);
}2Practical Example
Here is a real-world application of Handling Loading with Suspense showing how it is used in production React code.
function Page() {
return (
<>
<Suspense fallback={<p>Loading header...</p>}>
<LazyHeader />
</Suspense>
<Suspense fallback={<p>Loading content...</p>}>
<LazyContent />
</Suspense>
</>
);
}3Best Practices
Follow these guidelines when working with Handling Loading with Suspense:
1. Wrap a group of related lazy components in one shared Suspense boundary when they logically belong together and should appear as a group, not staggered in one by one
2. Nest separate, more granular Suspense boundaries around independent sections of a page when you want each section's loading state to be independent of the others
3. Design a fallback UI, like a skeleton screen, that closely matches the actual content's eventual layout, minimizing visual jank when the real content finally replaces it
Tip: Wrap multiple related lazy components in one single shared Suspense boundary when they should all appear together at once, avoiding a jarring, staggered sequence of separate loading indicators popping in one after another as each component individually finishes loading.
import React, { Suspense } from 'react';
const Chart = React.lazy(() => import('./Chart'));
const Table = React.lazy(() => import('./Table'));
function Dashboard() {
return (
<Suspense fallback={<p>Loading dashboard...</p>}>
<Chart />
<Table />
</Suspense>
);
}