# use()

> The `use()` API in React reads the value of a resource such as a `Promise` or context.

## How do I use the use() hook with promises in React?

The API that reads the value of a `Promise` or context during rendering. While the promise is pending, the component suspends and the nearest `Suspense` shows a fallback. Unlike hooks, it can be called inside conditions and loops.

- Topic: Hooks
- Type: hook, API

## Example

Wrong:

```jsx
'use client';
function Comments({ postId }) {
  const comments = use(fetch(`/api/posts/${postId}`).then((r) => r.json()));
  return <List items={comments} />;
}
```

Right:

```jsx
'use client';
function Comments({ commentsPromise }) {
  const comments = use(commentsPromise);
  return <List items={comments} />;
}
```

The promise is created once on the server and passed as a prop, so it stays the same across renders instead of suspending again.

## Common mistakes

- Creating a `fetch` promise inside a Client Component, which makes it suspend forever on every render.

## Key points

- Promises passed to `use()` come from a Server Component, a cache or a library, not created during client render.
- The component reading the promise is wrapped in `<Suspense>` and an error boundary.
- `use()` is not wrapped in `try`/`catch`, errors are handled by the error boundary.

## Interview questions

### Can I call use() inside an if statement?

Yes. Unlike hooks, `use()` can be called in conditions and loops, but it must still be called inside a component or a hook.

### use() vs useContext: which should I use?

Both read context. `use(Context)` also works after an early return or inside a condition, which `useContext` does not allow.

### Should I use use() in Server Components?

Usually not. In Server Components, `async` and `await` are simpler. `use()` is mainly for reading a promise in a Client Component.

## Related cards

- [`<Suspense>`](https://wonderium.dev/react/suspense.md)
- [Server Components](https://wonderium.dev/react/server-components.md)
- [useContext()](https://wonderium.dev/react/use-context.md)
- [cache()](https://wonderium.dev/react/cache.md)
- [Client Components](https://wonderium.dev/react/client-components.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/use
- Last updated: 2026-11-25
