CoreUI ONE — 250+ PRO components and 25+ admin templates for React, Angular, Vue, Bootstrap and Next.js, plus Data Grid, Scheduler, 4,300+ PRO icons and the Next.js boilerplate. One license. → See what you get

How to use Suspense in React

React Suspense provides a powerful way to handle loading states for asynchronous operations like lazy component loading and data fetching. As the creator of CoreUI, a widely used open-source UI library, I’ve used Suspense extensively in React applications to create smooth user experiences. From my experience with React, the most effective approach is to wrap components that might suspend with a Suspense boundary and provide appropriate fallback UI. This pattern creates declarative loading states and better error handling.

Wrap components that might suspend with Suspense and provide a fallback UI for loading states.

import { Suspense, lazy } from 'react'

const LazyComponent = lazy(() => import('./LazyComponent'))

function App() {
  return (
    <Suspense fallback={<div>Loading component...</div>}>
      <LazyComponent />
    </Suspense>
  )
}

// Multiple Suspense boundaries for granular loading
function Dashboard() {
  return (
    <div>
      <h1>Dashboard</h1>
      <Suspense fallback={<div>Loading charts...</div>}>
        <Charts />
      </Suspense>
      <Suspense fallback={<div>Loading table...</div>}>
        <DataTable />
      </Suspense>
    </div>
  )
}

The Suspense component catches any component that “suspends” (throws a promise) and displays the fallback UI until the promise resolves. The fallback prop accepts any React element, from simple text to complex loading components. You can create multiple Suspense boundaries to handle different loading states independently. When the suspended component loads successfully, React automatically replaces the fallback with the actual component.

This is the same Suspense pattern we use in CoreUI React templates to create seamless loading experiences in admin dashboards. For data fetching, combine Suspense with libraries like React Query or SWR that support Suspense mode for automatic loading state management.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Are you ready for CoreUI 3.0?
Are you ready for CoreUI 3.0?

Leave well alone?
Leave well alone?

What’s new and updated in CoreUI 3
What’s new and updated in CoreUI 3

Bootstrap Icons
Bootstrap Icons