Skip to main content

The use API and Suspense resources

React includes the use API:

const value = use(resource);

It can read a Context object or a Promise that participates in Suspense.

What use reads
Context
Read the nearest matching provider value.
Promise
Read a cached Promise; suspend while it is pending.

use is unusual: it is not a normal Hook, and it should not be taught as a generic data-fetching library.

use(context)​

import {use} from 'react';
import {ThemeContext} from './theme-context';

function Button() {
const theme = use(ThemeContext);
return <button className={theme}>Save</button>;
}

Unlike ordinary Hooks, use can be called in conditions and loops when reading a supported resource:

function Message({showTheme}) {
if (showTheme) {
const theme = use(ThemeContext);
return <p className={theme}>Hello</p>;
}

return <p>Hello</p>;
}

Do not generalize this exception to useState, useEffect, or other normal Hooks.

use(promise)​

function Product({productPromise}) {
const product = use(productPromise);
return <h1>{product.name}</h1>;
}

Wrap the reader in Suspense:

<Suspense fallback={<ProductSkeleton />}>
<Product productPromise={productPromise} />
</Suspense>
Promise read outcomeThe resource state determines which boundary participates.
Render component
Fulfilled
Return the resolved value and continue rendering.
Pending
Suspend and reveal the nearest Suspense fallback.
Rejected
Error propagates toward the nearest Error Boundary.

This gives loading, success, and failure a declarative boundary model.

Promise identity must be stable​

Do not create a new Promise during every render:

function Product({id}) {
const product = use(fetch(`/api/products/${id}`)); // ❌ uncached Promise
return <h1>{product.name}</h1>;
}
Why uncached Promises keep suspending
1Render creates Promise A
2Suspend
3Retry creates Promise B
4Suspend again
5No stable resource identity

Promises passed to use should come from a Suspense-compatible cache, framework/data layer, Server Component, or another architecture that preserves resource identity.

Tiny cache example for learning​

const cache = new Map();

function getProduct(id) {
if (!cache.has(id)) {
cache.set(
id,
fetch(`/api/products/${id}`).then(response => response.json()),
);
}

return cache.get(id);
}

function Product({id}) {
const product = use(getProduct(id));
return <h1>{product.name}</h1>;
}

This demonstrates stable Promise identity only. A production cache needs invalidation, deduplication, garbage collection, retries, authorization, server/client semantics, and more.

React primitive vs data layer​

React does not become your whole data architecture
React core
use(Promise) · Suspense · Error Boundaries · rendering coordination.
Framework / data library
Fetching policy · cache lifetime · invalidation · preloading · mutations · retries · server/client transfer.

use reads a resource. It does not decide how that resource should be fetched, refreshed, invalidated, or persisted.

Server-to-client Promise flow​

An RSC-capable architecture may create or obtain a Promise on the server, pass it through a supported boundary, and read it in a Client Component.

Server-created resource consumed on the client
Server Component
Creates or obtains a Promise.
Client Component
Calls use(promise) during render.
Suspense / streaming / hydration
Framework and React coordinate how the boundary reveals.

Exact serialization and server behaviour depend on the RSC-capable framework.

use(context) vs useContext​

Both can read Context.

Use useContext when ordinary top-level Hook structure is natural:

const theme = useContext(ThemeContext);

Use use when its resource-oriented or conditional calling behaviour is specifically useful:

if (shouldReadTheme) {
const theme = use(ThemeContext);
}

Do not refactor stable useContext code merely because use exists.

Do not bypass use​

Avoid manually inspecting Promise internals:

if (promise.status === 'fulfilled') {
return promise.value; // ❌ bypasses React's resource read
}

Use:

const value = use(promise);

Let React coordinate Suspense and tooling around the resource.

Suspense is not “catch every Promise”​

This does not make Suspense wait for an Effect fetch:

useEffect(() => {
fetch('/api/products').then(...);
}, []);

Effects run after commit. Suspense coordinates supported suspending resources such as lazy-loaded code, Promises read with use, and framework/library data sources designed for Suspense.

Preloading​

A resource can start before the component needs to read it.

Preload before navigation
1User signals likely intent
2Data layer starts resource
3User navigates
4Component calls use(resource)
5Resource is already pending or fulfilled

The data/cache layer owns starting the resource; use owns reading it during render.

Loading and error boundaries​

<ErrorBoundary fallback={<ProductError />}>
<Suspense fallback={<ProductSkeleton />}>
<Product productPromise={productPromise} />
</Suspense>
</ErrorBoundary>
Boundary responsibilities
Suspense Boundary
Expected waiting state.
Error Boundary
Failed rendering/resource state.

Boundary granularity matters. Prefer meaningful reveal units rather than one giant fallback around the whole app.

use and concurrency​

Suspending render work participates in React's concurrent rendering model. Learn use alongside Suspense, Transitions, useDeferredValue, streaming, selective hydration, and Server Components.

Production decision guide​

Should I build around use(Promise)?
Framework/data layer already owns data loading and cache?Use its supported pattern
Need a conventional client/server-state flow only?Suspense integration may be unnecessary
Intentionally building Suspense-compatible resource reading?Stable resource + use + Suspense + Error Boundary
Creating Promise directly during render?Redesign around cached resource identity

Common mistakes​

  • Creating uncached Promises during render.
  • Treating use as a fetch/cache/invalidation system.
  • Assuming Effect-based fetches trigger Suspense.
  • Calling ordinary Hooks conditionally because use can be conditional.
  • Reading Promise internals instead of passing the Promise to use.
  • Treating a tutorial Map as production cache architecture.

Interview questions​

Junior: What happens when use reads a pending Promise?

Mid-level: Why is use(fetch(url)) directly inside render usually incorrect?

Senior: What responsibilities belong to React's use/Suspense primitives versus a framework or server-state cache?

References​

Next​

Continue with <Activity> in React 19.2.