Skip to the page

React 19.x: Actions, forms and Server Components · senior

The use() API and browser()

use(resource) reads a promise (suspending until it resolves) or a context, and unlike hooks it can be called inside conditions and loops; the promise must come from a cache, a framework or a Server Component, never be created during render.

The notes

What you must know

  • const data = use(promise) suspends until the promise resolves; rejection goes to the nearest error boundary. Do not wrap use in try/catch.
  • use(ThemeContext) reads context and can be called after an early return or inside an if, which useContext cannot.
  • Promises must be cached so the same instance is reused across renders. React warns "A component was suspended by an uncached promise".
  • Streaming pattern: a Server Component starts a fetch without awaiting and passes the promise to a Client Component inside <Suspense>; the client calls use(promise). The resolved value must be serializable.
  • Do not read promise.status yourself to skip use; let React handle it.
  • use (reading context) is not supported in Server Components.
  • React 19.3: use(browser()) from react-dom suspends on the server (fallback goes into the HTML) and renders normally on the client after hydration. It can be called conditionally, for example only when no initialData exists.

The red pen

Common traps: mistake → fix

  • Mistake: "use(fetch(url)) in a client component"

    Fix: a new promise every render; it keeps suspending.

  • Mistake: "use is just useContext with a new name"

    Fix: it also reads promises and can be conditional.

  • Mistake: "Wrap use() in try/catch to handle errors"

    Fix: use an error boundary.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does use do that other hooks cannot?
  2. Why must the promise be cached or stable?
  3. When would you pass a promise from a Server Component to a Client Component and use it?
  4. How do you handle a rejected promise?
  5. What is use(browser()) for?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview