Under The Hood
frontend react React 19

The use() Hook: Conditional Promise and Context Unwrapping

Last updated
Prerequisites:
React Suspense
React Context API
Promises
  • react
  • use-hook
  • promises
  • context
  • suspense
  • react-19

Read at your depth

The practical view

The `use()` API in React 19 lets you read the value of a resource like a Promise or a React Context. Unlike all other React hooks (`useState`, `useEffect`, `useContext`), `use()` **can be called conditionally** inside `if` statements, loops, and after early returns. When passed a Promise, `use(promise)` suspends the component until the promise resolves, integrating seamlessly with `<Suspense>`.

The same idea in other frameworks

react equivalent
`const data = use(promise);` or `const theme = use(ThemeContext);`

Legacy vs modern

useEffect Data Fetching vs use() Promise Unwrapping

`useEffect` requires boilerplate loading states and causes waterfalls; `use()` unwraps promises directly under Suspense.

before → after
useEffect Fetch Pattern
useEffect(() => { fetch().then(setData); }, []); // ❌ Boilerplate + client waterfall
React 19 use() API
const user = use(userPromise); // ✅ NEW: Direct synchronous unwrap under Suspense

Interview gotchas

Context

Interviewers test your deep understanding of how React Suspense uses thrown promises under the hood.

The mechanical answer

No, you should **not** wrap `use(promise)` inside a standard JavaScript `try/catch` block. When a promise is pending, `use()` intentionally *throws the promise* to signal the nearest `<Suspense>` boundary. If your `try/catch` intercepts the thrown promise, Suspense will fail to catch it, causing the component to break.

Trap

To catch promise rejections from `use()`, use an **Error Boundary** or pass an already-caught promise with fallback data.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.