Course contentsShow
← React
Lesson 1477 of 2,39637. React 19 and BeyondFree lesson

Integrating use() with Suspense Boundaries

How use() triggers the nearest Suspense boundary while a promise is pending, creating declarative loading states.

Integrating use() with Suspense Boundaries

You'll learn: How use() automatically connects to your Suspense boundaries to show loading states when promises are pending.

The Automatic Suspense Connection

When you call use() with a promise in a component, React doesn't just wait silently. Instead, it triggers the nearest Suspense boundary up the component tree while that promise is pending. This creates a declarative loading pattern: you don't manually check if data is ready — React handles it.

Think of it like an emergency escalator in a building. When your component encounters a pending promise through use(), it sends a signal up through parent components until it finds a Suspense boundary, which then displays the fallback UI.

How It Works in Practice

function UserProfile({ userId }) {
  const user = use(fetchUser(userId)); // Promise passed to use()
  return <div>{user.name}</div>;
}

function App() {
  return (
    <Suspense fallback={<div>Loading user...</div>}>
      <UserProfile userId={123} />
    </Suspense>
  );
}

When UserProfile renders and the promise is still pending, use() suspends that component. React catches this suspension, walks up the tree, finds the Suspense boundary, and renders "Loading user..." instead. Once the promise resolves, React re-renders UserProfile with the actual data.

The Declarative Win

You don't write if (isLoading) return <Spinner />. The Suspense boundary declares where loading states appear, while use() declares what causes them. This separation makes your components cleaner and your loading states consistent across the app.

Key Takeaway: use() automatically triggers the nearest Suspense boundary when reading pending promises, creating a declarative loading pattern where boundaries handle where loading UI appears and use() determines when it's needed.