useTransition
React chapter 16 · React 18 · concurrent rendering · source: react.dev/reference/react/useTransition
The problem
Every keystroke redraws a slow list in the same update. The input has to wait for the list, so typing feels sticky.
The pattern that fixes it
Keep the input as urgent state. Wrap only the list state in startTransition. React paints the input first and renders the list when it can, and isPending tells you the list is catching up.
In plain words
Some updates must feel instant (the letter you typed) and some can take a moment (a big list that reacts to it). useTransition lets you label the second kind as "not urgent", so React does the urgent one first.
A waiter takes your order straight away (urgent), then the kitchen cooks it in the background (not urgent). He does not stand at the stove while you wait with the menu in your hand.
Terms
- urgent update
- Something the person expects to see right now, like text appearing in an input.
- transition
- An update you mark as non-urgent. React may pause or throw away its work if something urgent arrives.
- isPending
- A boolean from useTransition that is true while the transition has not finished yet.
- commit
- The moment React applies a finished render to the screen.
Going deeper
How does it work?
Normally a render runs to the end without stopping. Work inside startTransition is rendered in small slices. If you type again mid-way, React drops the half-done list render, paints the new input value first, then starts the list again with the newest text. That is why the list may commit fewer times than you typed letters.
Pitfalls: when it does nothing
It cannot make a slow render faster, it only reorders the work. If the input state itself goes inside the transition, typing lags again. If the list is not skipped while the input re-renders (no memo), the slow work still runs in the urgent update. Updates inside a transition must be synchronous state updates, not code after an await.
When not to use it, and alternatives
First make the render cheaper: fewer rows, virtualization (draw only visible rows), or move the filter into a worker. If you do not own the setter and only receive the value, use useDeferredValue (next chapter). The React Compiler can skip some wasted work, but it does not label updates as urgent or not.
Keep learning
- Previous: useEffectEvent
- Next: useDeferredValue
- Related: memo
- Related: useMemo
- Related: useCallback
- Related: Custom hooks
- Related: useEffectEvent
- Related: useDeferredValue
Overview
Type here (letters in the list highlight) try: garden Type "garden" for me Measured delays after your last keystroke Keystroke to input updated Keystroke to list updated Worst input delay so far opacity 150ms isPending is true: the list is still catching up. (It lives outside the memo so it cannot force the list to render.) Type a few letters, or press the button, then read the bars. Compare the SlowList badge with the number of keys you typed. Dropped half-finished renders never get counted. Badge and delay both come from real timing on your device. Real life: a product search box above a big grid that redraws for every letter. (The slowness is a small deliberate wait per row, about 105 ms in total, doubled in development.) Type garden quickly, or press the button. Read how long the input takes to update. Notice the list highlights words that contain your text. The slow list is blocking the letter you just typed. Same search box and grid. Try the fix, then try to break it by moving the input into the transition. How the update is split One update Input urgent, list in transition Everything in transition input waits too Good fit A cheap urgent value plus an expensive result. You own both setState calls. Not a fit The render itself is the problem: make it cheaper first. The value is a prop you do not control: see useDeferredValue. Press Type "garden" for me on each option and compare the worst input delay. On the fix, watch the SlowList badge. It usually rises by fewer than six, because React drops renders that were already out of date.
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.