use is a React Hook that lets you read the value of a resource like a Promise or Context.
use is different from other React Hooks because it can be called conditionally and inside loops. However, like other Hooks, it can only be called in components or other Hooks.Parameters
Promise<T> | Context<T>
required
The resource you want to read a value from. A resource can be a Promise or a Context.
- Promise: React will suspend until the Promise resolves, then return the resolved value
- Context: Works like
useContext, returning the current context value
Returns
Returns the resolved value of the resource (the resolved value of the Promise or the context value).Usage
Reading context with use
When a Context is passed touse, it works similarly to useContext:
useContext, use can be called conditionally and in loops:
Streaming data from the server to the client
Data can be streamed from the server to the client by passing a Promise as a prop:When passing a Promise from a Server Component to a Client Component, its resolved value must be serializable to pass between server and client.
Dealing with rejected Promises
Wrap your component with an error boundary to handle rejected Promises:Common Patterns
Fetching data with use
- Basic
- With Error Handling
Conditional data fetching
Reading multiple resources
Using with Context
Parallel data fetching
TypeScript
Troubleshooting
”use” is not a function or is undefined
Make sure you’re using a version of React that supportsuse (React 19+):
The component suspends but never resolves
Make sure your Promise eventually resolves:Can I use “use” with useMemo?
No,use reads resources synchronously. For Promises, wrap the component in Suspense:
Should I always use “use” for context?
No,useContext is still the primary way to read context. Use use when you need conditional context reading:
Best Practices
Wrap in Suspense
Always wrap components that use Promises with Suspense:Add error boundaries
Start fetching early
Don’t create promises during render
When to use “use”
Useuse when:
- ✅ Reading a Promise in a component
- ✅ You need conditional Hook calls
- ✅ Streaming data from server to client
- ✅ Reading context conditionally
useContext when:
- ✅ Reading context unconditionally
- ✅ You prefer explicit Hook naming
useEffect + useState when:
- ✅ You need to fetch data client-side without Suspense
- ✅ You need fine-grained loading states
- ✅ You’re not using React Server Components