use() in Client Components: Consuming Server Promises
You'll learn how to pass promises from Server Components to Client Components and unwrap them with use() for streaming data.
The Server-to-Client Promise Bridge
In React Server Components architectures, you can create a promise on the server and pass it directly to a Client Component as a prop. The Client Component can then use the use() hook to unwrap that promise, triggering Suspense boundaries while the data streams in.
This pattern lets you start fetching data on the server but defer the actual rendering decision to the client, combining the best of both worlds: server-initiated data fetching with client-side progressive rendering.
How It Works
The Server Component initiates a fetch and passes the promise itself (not the resolved data) to a Client Component:
// ServerComponent.js (Server Component)
import ClientDisplay from './ClientDisplay';
async function getUser(id) {
const res = await fetch(`/api/users/${id}`);
return res.json();
}
export default function UserPage({ userId }) {
const userPromise = getUser(userId); // Promise, not awaited!
return <ClientDisplay userPromise={userPromise} />;
}
The Client Component uses use() to read the promise:
// ClientDisplay.js (Client Component)
'use client';
import { use, Suspense } from 'react';
export default function ClientDisplay({ userPromise }) {
return (
<Suspense fallback={<div>Loading user...</div>}>
<UserDetails userPromise={userPromise} />
</Suspense>
);
}
function UserDetails({ userPromise }) {
const user = use(userPromise); // Unwraps the promise
return <h1>{user.name}</h1>;
}
The promise starts resolving on the server, streams to the client, and use() waits for completion while Suspense shows the fallback.
Key Takeaway: You can pass promises from Server Components to Client Components and unwrap them with use(), enabling server-initiated fetches with client-side streaming and Suspense integration.