The use hook
React 19's use() reads a promise or context value and, unlike every other hook, can be called inside an if, a loop, or after an early return.
Suspense for data fetchingCaching, invalidation, and mutations
The use hook
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- use() can read two different things: a promise, which suspends the component until it resolves (pairing with Suspense exactly like useSuspenseQuery does), or a context value, as a conditional alternative to useContext.
- use() is not subject to the Rules of Hooks. It can be called inside an if statement, inside a loop, or after an early return — every other hook would break React's call-order tracking if you tried that.
- React can allow this because use() doesn't rely on call order or a fixed hooks list the way useState or useEffect do; it reads from React's current rendering context at the moment it's called, so calling it conditionally doesn't desynchronize anything.
- That makes use() the deliberate exception to a rule taught earlier in this roadmap specifically because of how it's implemented, not a sign that the Rules of Hooks are being relaxed generally for every hook.
- Passing use() a promise created fresh on every render — rather than one cached by something like useSuspenseQuery or React's cache() — causes the component to suspend and refetch on every render, a real performance trap.
- use() does not replace useContext for the common case; useContext still works and is still simpler when you always need the value unconditionally at the top of a component.
A hook that breaks its own rulebook
Several lessons back, this roadmap taught the Rules of Hooks: always call hooks at the top level of a component, never inside a condition, a loop, or after an early return, because React tracks hooks by the order they’re called in across renders. Break that order and React’s internal bookkeeping — which piece of state belongs to which useState call — falls apart.
React 19’s use() is the one hook where that rule doesn’t apply. You can call it inside an if, inside a loop, after a return, anywhere a function call is syntactically legal:
function Message({ messagePromise, showDetails }) {
if (!showDetails) {
return <p>Loading a message…</p>;
}
// calling use() after an early return — illegal for every other hook
const message = use(messagePromise);
return <p>{message}</p>;
}
That if (!showDetails) return ... followed by a hook call below it would be a Rules-of-Hooks violation for useState or useEffect. For use(), it’s the intended usage pattern.
Why React can allow this
The Rules of Hooks exist because useState, useEffect, and the rest rely on a fixed, order-indexed list that React builds up as it walks through a component function’s hook calls on each render. The first useState call always maps to the first slot in that list, the second to the second slot, and so on — call them in a different order (because one got skipped inside a condition) and React hands back the wrong state to the wrong call.
use() isn’t implemented that way. Rather than occupying a slot in that ordered list, it reads directly from React’s current rendering context at the moment it’s called — the promise or context value it’s handed, resolved against whatever React is doing right now. There’s no persistent per-call slot to desynchronize, so calling it zero times, once, or five times across different branches of the same render doesn’t break anything the way skipping a useState call would. This is a deliberate, narrow exception built into how use() itself works, not evidence that the Rules of Hooks are being loosened for hooks generally — every other hook still needs the fixed call order.
Reading a promise: pairing with Suspense
The first thing use() can read is a promise, and doing so suspends the calling component exactly the way a thrown promise from useSuspenseQuery does — use() needs a <Suspense> boundary above it to catch that suspension and show a fallback.
import { use, Suspense } from "react";
function Comments({ commentsPromise }) {
// suspends until commentsPromise resolves
const comments = use(commentsPromise);
return (
<ul>
{comments.map((c) => (
<li key={c.id}>{c.text}</li>
))}
</ul>
);
}
function CommentsSection({ commentsPromise }) {
return (
<Suspense fallback={<p>Loading comments…</p>}>
<Comments commentsPromise={commentsPromise} />
</Suspense>
);
}
The caveat that matters here: use() has no cache of its own. If commentsPromise were created fresh inside CommentsSection on every render — use(fetch(...)) written directly in the component body, for instance — Comments would suspend and effectively re-fetch on every single render, which is a real performance trap. The promise needs to come from something that caches it across renders and only creates a new one when the underlying query key actually changes, which in practice means passing in a promise sourced from useSuspenseQuery or from React’s own cache() function for server-rendered data, not constructing one inline.
Reading context conditionally
The second thing use() can read is a context value, as an alternative to useContext — and because use() is exempt from the Rules of Hooks, it can do this inside a condition:
function Banner({ showTheme }) {
if (!showTheme) {
return <div className="banner">Welcome</div>;
}
// reading context after an early return — not possible with useContext
const theme = use(ThemeContext);
return <div className={`banner banner--${theme}`}>Welcome</div>;
}
useContext(ThemeContext) could not be written after that early return; it would have to run unconditionally at the top, even on the branch where its value is never used. use(ThemeContext) can be placed exactly where it’s needed. For the common case — a component that always needs the context value regardless of any branch — useContext is still simpler and there’s no reason to switch; use() earns its keep specifically when the read is genuinely conditional.
What the video covers
Jack Herrington frames his video around a real gotcha: calling use() with a promise that gets recreated on every render, and how that quietly tanks performance by causing repeated suspension. It’s a sharp, practical look at the API from someone with a strong React/TypeScript track record, but it’s framed as a warning about misuse rather than a ground-up introduction to use()’s two read modes or its Rules-of-Hooks exemption — both of which this lesson’s sections above cover directly. The Tom Dohnal link below is a more from-scratch, 2025 introduction if you want that framing first.
Where this fits
This closes out Suspense and concurrent rendering as a topic. The next group moves from rendering mechanics to where components actually run, starting with CSR, SSR, and static rendering concepts.
Check yourself
What are the two kinds of things the use() hook can read?
A promise, which suspends the calling component until the promise resolves and pairs with a Suspense boundary the same way a Suspense-compatible data hook does, or a React context value, which use() can read as a conditional alternative to useContext.
A developer tries to call useState inside an if block and React throws an error about hooks being called in a different order than the previous render. Would use() have the same problem in the same spot?
No. The Rules of Hooks exist because hooks like useState and useEffect rely on being called in the same order on every render to match their internal state to the right slot; use() doesn't depend on call order the same way, so React explicitly allows it inside conditionals, loops, and after early returns where other hooks cannot go.
Why is use() exempt from the Rules of Hooks when no other hook is?
Because of how it's implemented: other hooks rely on a persistent, order-indexed list React builds up across a component's hook calls, while use() reads directly from React's current rendering context at the moment it's invoked rather than from a position in that list, so calling it conditionally never desynchronizes anything.
What performance mistake can happen if you call use() with a brand-new promise created inside the component's render on every render?
The component suspends and effectively refetches on every render, because use() has no cache of its own — it treats each new promise as new work to wait on. The promise needs to come from something that caches it across renders, like useSuspenseQuery or React's cache() function, not be created fresh inline.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.