Capítulo 91 de 116
use(resource) reads the value of a promise or a Context directly during render — unlike other Hooks, it can be called conditionally and inside loops, and reading a pending promise causes the component to suspend into the nearest Suspense boundary.
use(promise) suspends the component until the promise resolves, then returns its resolved value directly (or throws if it rejects, catchable by an error boundary); use(SomeContext) reads a Context value, behaving like useContext but callable conditionally.use can be called inside if statements, loops, and after early returns, specifically because of how it integrates with Suspense/conditional data reading; this makes it structurally different from every other built-in Hook covered so far.Suspense: a component calling use(promise) on a still-pending promise suspends exactly like a lazy-loaded component (Ch 87/70) — the nearest Suspense boundary's fallback shows until it resolves.useContext: for Context specifically, use gives the added flexibility of conditional reads that useContext doesn't allow, while behaving identically otherwise.function Comments({ commentsPromise }) {
const comments = use(commentsPromise); // suspends until resolved
return comments.map(c => <Comment key={c.id} comment={c} />);
}
Suspense boundary until it resolves rather than manually managing loading state.use is the one built-in Hook exempt from the "call only at the top level" rule — it can be conditional, which is central to how it's meant to be used.use over useContext specifically when you need to read it conditionally; otherwise they're interchangeable.