useTransition and useDeferredValue – React Hooks

Introduction:
Have you ever typed into a search box and felt the letters appear late, as if the keyboard were stuck? Or clicked a tab and watched the whole page freeze for a moment before anything happened? In React, this usually happens when one small update (a keystroke or a click) causes a big, slow re-render, such as filtering a long list or drawing a heavy chart.
By default, React treats every state update as equally urgent. While it is busy re-rendering 5,000 list items, it cannot do anything else, including showing the letter you just typed.
React 18 introduced concurrent rendering, and with it two hooks that let you tell React which updates are urgent and which can wait:
- useTransition marks a state update as non-urgent (a “transition”).
- useDeferredValue gives you a lagging copy of a value that can update a little later.
React 19 made transitions even more useful by allowing async functions inside them. In this lesson we will see the problem in action, fix it with both hooks, and learn exactly when to use which. It builds on useState, useMemo and the Optimizing Performance lesson.
All examples were run with React 19.3 in a real Chromium browser, and the measurements in the comments are the real results.
Part 1: The Problem
1. Urgent vs Non-Urgent Updates:
Think of a restaurant. When a customer asks for the bill, the waiter should respond right away. Cleaning the tables can wait a few seconds. If the waiter insisted on cleaning every table before answering anyone, customers would feel ignored, even though the waiter is working hard.
React updates are similar:
- Urgent updates respond directly to the user: typing, clicking, pressing a key. If they are slow, the app feels broken.
- Non-urgent updates show the *result* of that action: a filtered list, a new tab’s content, a chart. A short delay is fine, as long as the app stays responsive.
Without any hints, React handles both in one go, so the slow part blocks the fast part.
2. A Slow Search List:
Here is a search box that filters a list. To simulate a heavy component, each list item deliberately wastes 1 ms when it renders, so the list of 250 items takes about a quarter of a second:
import { useState, memo } from "react";
function slow(ms) {
const end = performance.now() + ms;
while (performance.now() < end) {} // simulate expensive work
}
function SlowItem({ text }) {
slow(1);
return <li>{text}</li>;
}
const SlowList = memo(function SlowList({ query }) {
const items = [];
for (let i = 0; i < 250; i++) {
items.push(<SlowItem key={i} text={`${query} result ${i}`} />);
}
return <ul>{items}</ul>;
});
function Search() {
const [query, setQuery] = useState("");
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<SlowList query={query} />
</>
);
}
Every keystroke updates query, and React must re-render the whole slow list before it can show the new letter in the input.
In our test, typing the word hello (five keys, 30 ms apart) took 1,512 ms to finish. The input could not keep up with the keyboard, because each letter waited for the list.
Part 2: useDeferredValue
3. Fixing the Search with useDeferredValue:
useDeferredValue takes a value and returns a deferred version of it. On an urgent update, React first re-renders with the old deferred value (which is fast, because nothing changed for the slow list), and then tries to re-render with the new value in the background:
import { useState, useDeferredValue } from "react";
function Search() {
const [query, setQuery] = useState("");
const deferredQuery = useDeferredValue(query);
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<SlowList query={deferredQuery} />
</>
);
}
Only one line changed: the list now receives deferredQuery instead of query. The input still uses query, so it always shows exactly what you typed.
With this change, typing hello took 199 ms instead of 1,512 ms. The letters appeared immediately, and the list caught up once typing paused.
Two details make this work:
- The background render can be interrupted. If you type another letter while React is rendering the list for the previous one, React throws that unfinished work away and starts again with the newest value. It never wastes time finishing a list nobody will see.
- The slow component must be wrapped in
memo. During the urgent render,SlowListreceives the same olddeferredQuery, somemolets React skip it completely. Withoutmemo, the slow list would re-render during the urgent render too, and the benefit would disappear.
4. Showing That Content Is Stale:
While the list is catching up, it is showing results for an older query. You can detect this by comparing the two values, and give the user a hint:
function Search() {
const [query, setQuery] = useState("");
const deferredQuery = useDeferredValue(query);
const isStale = query !== deferredQuery;
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} />
<p>{isStale ? "Updating..." : "Up to date"}</p>
<div style={{ opacity: isStale ? 0.5 : 1 }}>
<SlowList query={deferredQuery} />
</div>
</>
);
}
In our test, right after typing ab the screen showed:
input: "ab"
status: "Updating..."
first item: " result 0" // still the old (empty) query
And a moment later:
input: "ab"
status: "Up to date"
first item: "ab result 0"
Dimming the old results is a common pattern. The user sees that their input was received and that new results are on the way, instead of a frozen screen or a flashing spinner.
5. The initialValue Option (React 19):
React 19 added an optional second argument: the value to use on the very first render. This is useful when the real value is expensive, because the first paint can show something cheap and the real content follows right after:
function Results() {
const [query] = useState("react");
const deferredQuery = useDeferredValue(query, "");
console.log(`query=${query} deferred=${JSON.stringify(deferredQuery)}`);
return <SlowList query={deferredQuery} />;
}
// Console (real output):
// query=react deferred=""
// query=react deferred="react"
The component rendered twice: first with the initial value "", then in the background with "react". Without the second argument, the first render would use "react" directly.
Part 3: useTransition
6. Basic Syntax:
useTransition works from the other side. Instead of deferring a value, you wrap the state update itself and mark it as non-urgent:
const [isPending, startTransition] = useTransition();
startTransition(() => {
setTab("posts"); // this update is a transition
});
It returns two things:
- isPending:
truewhile the transition is still rendering. Use it to show a hint. - startTransition: a function that runs your callback and marks every state update inside it as a transition.
7. Tabs That Stay Clickable:
Here is a classic example: three tabs, one of which (Posts) is slow to render:
import { useState, useTransition } from "react";
function Tabs() {
const [tab, setTab] = useState("about");
const [isPending, startTransition] = useTransition();
function select(next) {
startTransition(() => {
setTab(next);
});
}
return (
<>
<button onClick={() => select("about")}>About</button>
<button onClick={() => select("posts")}>Posts</button>
<button onClick={() => select("contact")}>Contact</button>
{isPending && <p>Loading...</p>}
{tab === "about" && <About />}
{tab === "posts" && <Posts />} {/* 250 slow items */}
{tab === "contact" && <Contact />}
</>
);
}
Our test clicked Posts, and then Contact before Posts had finished. This is what the browser showed:
right after clicking Posts: "Loading..." + the About page still visible
after clicking Contact: no "Loading...", the Contact page
Three useful things happened:
- The old tab stayed on screen while the new one rendered, instead of a blank page.
- isPending let us show “Loading…” straight away.
- The click on Contact interrupted the unfinished Posts render. Without a transition, the page would have frozen until Posts finished, and only then reacted to the second click.
8. Async Actions in Transitions (React 19):
In React 19, the function you pass to startTransition can be async. isPending stays true for the whole time, including while you wait for a network request. This replaces a lot of manual isLoading state:
function fakeSave(name) {
return new Promise((resolve) =>
setTimeout(() => resolve(`Saved "${name}"`), 800)
);
}
function SaveName() {
const [name, setName] = useState("Zara");
const [message, setMessage] = useState("");
const [isPending, startTransition] = useTransition();
function handleSave() {
startTransition(async () => {
const result = await fakeSave(name);
startTransition(() => {
setMessage(result);
});
});
}
return (
<>
<input value={name} onChange={(e) => setName(e.target.value)} />
<button onClick={handleSave} disabled={isPending}>
{isPending ? "Saving..." : "Save"}
</button>
<p>{message}</p>
</>
);
}
// 100 ms after clicking: button "Saving..." (disabled), message ""
// after the save: button "Save", message 'Saved "Zara"'
Notice the second startTransition around setMessage. Any state update that happens after an await is no longer inside the original transition, so React’s documentation recommends wrapping it again. This is a current limitation of how JavaScript tracks async code, and it may be removed in a future version of React.
React calls an async transition like this an Action. Newer hooks like useActionState and the <form action={...}> prop are built on the same idea, and we will cover them in a later lesson.
9. startTransition Without the Hook:
React also exports a plain startTransition function. It does the same thing but gives you no isPending. Use it outside components, for example in a data library or a router, or when you don’t need a pending indicator:
import { startTransition } from "react";
function goToPage(page) {
startTransition(() => {
setPage(page);
});
}
Part 4: Choosing the Right Hook
10. useTransition vs useDeferredValue:
Both hooks do the same job underneath: they let React render something in the background, at lower priority, and interrupt it if something more urgent happens. The difference is where you have control:
- useTransition wraps the state update. Use it when you own the code that calls
setState, such as a click handler. - useDeferredValue wraps the value. Use it when you only receive the value, for example as a prop from a parent or from a library hook, and can’t change how it is set.
A quick way to decide:
- Clicking tabs, changing pages, submitting a form: useTransition (you also get
isPending). - A slow component that receives a fast-changing prop, like a search query or slider value: useDeferredValue.
11. Why Not Debounce?:
Before these hooks, the usual fix for a laggy search was debouncing: waiting, say, 300 ms after the last keystroke before updating the list. That works, but it has two problems:
- It always waits the full delay, even on a fast computer that could have shown results instantly.
- Once the slow render starts, it still blocks the page until it finishes.
useDeferredValue has no fixed delay. On a fast device, the list updates almost immediately; on a slow device, it falls behind gracefully, and it never blocks typing. Debouncing is still the right tool for limiting network requests (you don’t want an API call per keystroke), but for slow rendering, deferring is better.
12. Common Mistakes:
- Using a transition for a controlled input.
startTransition(() => setQuery(e.target.value))on the input’s own state makes typing feel broken, because the input itself becomes non-urgent. Keep the input state urgent and defer the *slow part* instead, withuseDeferredValueor with a second state updated in a transition. - Forgetting
memo.useDeferredValueonly helps if the slow component can skip the urgent render. Wrap it inmemoand make sure its props don’t change on every render (for example, a new object or function each time). - Expecting it to make code faster. These hooks do not make a slow component faster. They make the app stay responsive while the slow work happens. If a component is very slow, also look at useMemo, virtualised lists, or reducing the work itself.
- Calling startTransition with a delay. The callback must update state right away.
startTransition(() => setTimeout(() => setTab(t), 100))does not mark the update as a transition, because it runs later, outside the callback. - Putting side effects inside. The function passed to
startTransitionshould only update state (and, in React 19, await async work). Don’t rely on it for logging or analytics timing.
Conclusion:
React treats every update as urgent unless you say otherwise. useTransition lets you mark a state update as non-urgent, gives you an isPending flag, keeps the old screen visible while the new one renders, and in React 19 can wrap async work such as saving data. useDeferredValue gives a slow component a lagging copy of a fast-changing value, so typing stays smooth while results catch up.
In our tests, the same slow search went from 1,512 ms to 199 ms to type a five-letter word, just by deferring one value and wrapping the list in memo.
In the next lesson we will learn about Error Boundaries, which stop one broken component from crashing your whole React app.


