Reading Promises with use() in Components
You'll learn how the use() hook unwraps a promise's value directly during render, automatically triggering Suspense while waiting.
The Core Idea
The use() hook lets you read a promise's resolved value right inside your component's render logic. When you call use(myPromise), React doesn't block or throw an error—instead, it suspends the component (triggering the nearest Suspense boundary's fallback) until the promise resolves, then automatically re-renders with the resolved value.
Think of it like ordering at a drive-through: you pull up (use(promise)), the restaurant tells you to wait (Suspense fallback), and once your order is ready, they hand it to you (the resolved value).
How It Works
function UserProfile({ userPromise }) {
// This line "reads" the promise
const user = use(userPromise);
return <div>Hello, {user.name}!</div>;
}
// In parent component:
<Suspense fallback={<Spinner />}>
<UserProfile userPromise={fetchUser()} />
</Suspense>
While userPromise is pending, the UserProfile component suspends. React shows the <Spinner /> fallback. Once the promise resolves, use() returns the actual user data, and the component renders normally.
Key Differences from Then/Catch
Unlike .then() callbacks or async/await (which you can't use directly in render), use() lets you treat async data as if it were synchronous. No need for loading state variables or effects—Suspense handles the coordination automatically.
Key Takeaway: use() unwraps a promise's value during render, seamlessly integrating with Suspense to show fallback UI while the promise is pending—no manual loading states required.