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.
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>
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>;
}
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
use(Promise) · Suspense · Error Boundaries · rendering coordination.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.
use(promise) during render.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.
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 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
Common mistakes
- Creating uncached Promises during render.
- Treating
useas a fetch/cache/invalidation system. - Assuming Effect-based fetches trigger Suspense.
- Calling ordinary Hooks conditionally because
usecan be conditional. - Reading Promise internals instead of passing the Promise to
use. - Treating a tutorial
Mapas 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
- https://react.dev/reference/react/use
- https://react.dev/reference/react/Suspense
- https://react.dev/blog/2024/12/05/react-19
Next
Continue with <Activity> in React 19.2.