useDeferredValue
React chapter 17 · React 18 · deferred values · source: react.dev/reference/react/useDeferredValue
The problem
A heavy child receives a value that changes on every keystroke. You only hold the value, not the setter, so you cannot wrap anything in startTransition, and typing gets sticky.
The pattern that fixes it
useDeferredValue(query) gives you a copy that trails behind during urgent updates. Show the input with query and the heavy child with the deferred copy, and wrap the child in memo so it can really skip.
In plain words
You can tell React "use the old value for this part of the screen for now, and catch up when you have a free moment". The input stays instant and the slow part follows right behind.
A scoreboard operator updates the big display only when the play settles. Meanwhile the referee (the input) already knows the new score.
Terms
- deferred value
- A copy of a value that may lag behind the real one while React is busy with something more urgent.
- stale
- Showing the previous result because the newest one is not ready yet.
- memo
- A wrapper that lets a component skip rendering when its props did not change.
Going deeper
How does it work?
On an urgent update React first renders with the old deferred value, so the heavy child gets identical props and can be skipped. Right after, it starts a second, interruptible render with the new value. If you type again before it finishes, that background render is thrown away and restarted with the newest text.
Pitfalls: when it does nothing
If the heavy child is not wrapped in memo, it still re-renders during the urgent update (with the old value), so the lag stays. It also changes nothing if the child is cheap, and it never makes a single render faster. Passing a fresh object each time as the deferred value defeats the comparison, so defer primitives like text.
When not to use it, and alternatives
If you own both state updates, useTransition (previous chapter) gives you an isPending flag for free. For network requests use debouncing or a data library, because deferring does not delay the request itself. The React Compiler can add the memo part for you, but you still choose what to defer.
Keep learning
- Previous: useTransition
- Next: useSyncExternalStore
- Related: memo
- Related: useMemo
- Related: useCallback
- Related: Custom hooks
- Related: useEffectEvent
- Related: useTransition
Overview
Type here (letters in the grid highlight) try: garden Type "garden" for me Measured delays after your last keystroke Keystroke to input updated Keystroke to Results updated Worst input delay so far opacity 150ms Type a few letters, or press the button, then read the bars. Results was not memoized, so it re-rendered during the urgent update (with the old value) and paid the whole cost anyway. The urgent render gave Results identical props, so React skipped it and rendered the new text later. Badge and delay both come from real timing on your device. Real life: an autocomplete whose results panel is a heavy component you receive the text for. (The slowness is a small deliberate wait per row, about 105 ms in total, doubled in development.) , hot: true, note: Type garden or press the button and read the input delay. Ask yourself: where would you put startTransition? There is only one state, so there is nothing to split. Same autocomplete. Try the fix, then try to break it by taking memo away. How Results gets its text Straight from query Deferred + memo Deferred, no memo not memoized: renders anyway You own the setters. You get isPending. You only hold the value (a prop, a hook result). Compare deferred !== query to know it is behind. Press Type "garden" for me on all three options and compare the worst input delay. In Deferred + memo, watch the strip: deferred turns red while it trails and catches up a moment later.
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.