use()
The React 19 API that reads a value from a Promise or a context, and unlike hooks may be called inside conditions and loops.
In more detail
use(promise) suspends the component until the promise settles, showing the nearest Suspense fallback, then returns the resolved value; a rejection goes to the nearest error boundary. use(Context) works like useContext but can be called after an early return. It must still be called during rendering of a component or hook.
Example
const user = use(userPromise);Related terms
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- Suspense — A React component that shows a fallback, such as a spinner or skeleton, while components inside it are waiting for something to load.
- React Context — A React feature that lets a parent component make a value available to every component below it without passing it as props.
- error boundary — A class component that catches errors thrown while rendering its children and shows a fallback UI instead of crashing the whole app.
Taught in
- useOptimistic: Instantaneous UI Updates with Rollback — React 19 & Modern Component Architecture
- The use() Hook: Reading Promises And Context Directly — React 19 & Modern Component Architecture
- Suspense Architecture: Promises, Fallbacks, And Co-ordination — React 19 & Modern Component Architecture