Skip to content
HooksChapter 24 / 37Advanced4 min read

The use() API

Learn how the React use API reads a Promise or Context during render, how it works with Suspense, and how it differs from other hooks.

On this page

1. What is the use() API?

use(promise) suspends the component until the Promise resolves, and the fallback of the closest Suspense boundary is shown. When it resolves, you get the value.

use(Context) works just like useContext, but it is more flexible.

2. Why does it matter?

Before, waiting for data meant writing useEffect + useState + a loading flag.

The old wayWith use()
Fetch in useEffect, data in useStateRead the Promise directly with use
An isLoading check in every componentThe Suspense fallback shows loading
You manage the error state yourselfAn Error Boundary catches the error
useContext cannot run inside a conditionuse can run inside an if

3. Where is it used?

SituationHow
Passing a Promise from a Server Component to a Client ComponentThe server fetch Promise goes in a prop, and the client calls use(promise)
A cached Promise from a framework or libraryuse(cachedPromise)
Reading Context after a conditionuse(ThemeContext) inside an if
Context after an early returnuseContext cannot do this, use can

4. How does it work?

The use(promise) flow
The component calls use(promise) during render
If the Promise is pending, the component suspends
The closest Suspense fallback is shown
The Promise resolves and React renders again
use returns the resolved value

If the Promise is rejected, the closest Error Boundary shows the error.

5. Code example

A Promise from the server to the client

tsx
import { Suspense } from "react";
import { Comments } from "./comments";

export default async function PostPage() {
  const commentsPromise = fetch("https://api.example.com/comments").then((r) => r.json());

  return (
    <Suspense fallback={<p>Loading comments...</p>}>
      <Comments commentsPromise={commentsPromise} />
    </Suspense>
  );
}
tsx
"use client";

import { use } from "react";

type Comment = { id: number; text: string };

export function Comments({ commentsPromise }: { commentsPromise: Promise<Comment[]> }) {
  const comments = use(commentsPromise);
  return (
    <ul>
      {comments.map((c) => (
        <li key={c.id}>{c.text}</li>
      ))}
    </ul>
  );
}

Context inside a condition

tsx
import { use, type ReactNode } from "react";
import { ThemeContext } from "./theme-context";

export function Heading({ show, children }: { show: boolean; children: ReactNode }) {
  if (!show) {
    return null;
  }
  const theme = use(ThemeContext);
  return <h2 className={theme}>{children}</h2>;
}

How does the code work?

PartMeaning
fetch(...) in the Server ComponentCreates a Promise without await, so the page is not blocked
<Suspense fallback>Shows loading text until the data arrives
use(commentsPromise)Gets the resolved data on the client
if (!show) return nulluse can still run after an early return
use(ThemeContext)Like useContext, but conditional

6. Common mistakes

Mistake: Creating a new Promise during a Client Component's render

Why? A new Promise is created on every render, so the component suspends again and again and never seems to resolve.

Better: Pass the Promise down from a Server Component, or use a stable Promise from a caching library or framework.

Mistake: Wrapping use in try catch

Why? use suspends by throwing a special exception, and try catch breaks that.

Better: Use an Error Boundary for errors, or add a catch to the Promise and give a fallback value.

Mistake: Forgetting the Suspense boundary

Why? A component that suspends without Suspense pushes the loading state all the way up and the whole page gets stuck.

Better: Always put a component that calls use(promise) inside a suitable Suspense.

Interview tip

use is an API, not a hook, which is why it can run inside a condition. It does not cache data by itself. In real apps, the Promise comes from a framework (like Next.js) or a library like TanStack Query.

7. What to learn before and after

Final quick revision

PointDetail
What it isAn API for reading a Promise or Context in render
Promise pendingThe component suspends and the Suspense fallback shows
Promise rejectedAn Error Boundary handles it
Conditional callYes, even inside if and loops
Not allowedInside try/catch, or creating a new Promise during render