
When a state update triggers heavy work — filtering a 10k-row list, parsing a big JSON blob, recomputing a chart — React blocks the main thread until the render finishes. The result: typing in an input feels laggy, buttons don’t light up, the whole tab freezes for a moment. That “jank” everyone blames on React is usually your synchronous render work, not the framework.
React 18’s concurrent features give you two small hooks to fix this without restructuring your app: useTransition and useDeferredValue.
The problem: one update blocks everything
Here is the trap. A single onChange both updates the input value and runs an expensive filter in the same render:
function Search() {
const [query, setQuery] = useState("");
const [list, setList] = useState([]);
function handleChange(e) {
setQuery(e.target.value);
// expensive: blocks the keypress from painting until done
setList(BIG_DATA.filter(d => d.name.includes(e.target.value)));
}
return (
<>
<input value={query} onChange={handleChange} />
<Results items={list} />
</>
);
}
Every keystroke waits for BIG_DATA.filter(...) to finish before the input repaints. On a slow machine that is a visible freeze.
useTransition: mark an update as “non-urgent”
Wrap the expensive update in startTransition. React keeps the urgent update (the input) responsive and renders the slow one when the browser is idle — and it can even interrupt and throw away stale results if a newer transition arrives.
import { useTransition, useState } from "react";
function Search() {
const [query, setQuery] = useState("");
const [list, setList] = useState([]);
const [isPending, startTransition] = useTransition();
function handleChange(e) {
const value = e.target.value;
setQuery(value); // urgent: input stays snappy
startTransition(() => {
setList(BIG_DATA.filter(d => d.name.includes(value))); // deferred
});
}
return (
<>
<input value={query} onChange={handleChange} />
{isPending && <span>Updating…</span>}
<Results items={list} />
</>
);
}
startTransition returns [isPending, startTransition]. Use isPending to show a subtle loading hint without blocking input.
useDeferredValue: defer a derived value
If the expensive part is a value another component reads (not a setter you control), useDeferredValue is the cleaner fit. It hands you a “laggy” copy of a value that React updates in the background:
import { useDeferredValue, useMemo, useState } from "react";
function Search() {
const [query, setQuery] = useState("");
const deferredQuery = useDeferredValue(query); // trails `query` by a frame
const list = useMemo(
() => BIG_DATA.filter(d => d.name.includes(deferredQuery)),
[deferredQuery]
);
return (
<>
<input value={query} onChange={e => setQuery(e.target.value)} />
<Results items={list} />
</>
);
}
The input keeps the fresh query immediately; deferredQuery catches up a frame later, so the heavy useMemo runs off the critical path.
When to use which
useTransition— you control the setter and want to mark an update as low priority (e.g. asetStateinside an event handler).useDeferredValue— you receive a prop/value and want a background copy to feed expensive rendering, with zero changes at the call site.- Both are interruptible: React discards outdated concurrent work instead of finishing it, so fast typers never queue up stale renders.
Gotchas
- These don’t make the work faster — they make it non-blocking. If a single render still takes 2s, split the data or virtualize the list (e.g.
react-window). - Don’t wrap every update. Only defer genuinely expensive ones; overusing it just adds latency.
useDeferredValuereturns the current value on the first render, then defers on subsequent ones — guard againstundefinedif you initialize loosely.- They require React 18+ and only help with render/commit work, not blocking
fetchorsetTimeoutcallbacks (those need web workers orrequestIdleCallback).
TL;DR
If an input or button feels frozen while React “thinks”, you are doing synchronous render work on the urgent path. Move it off the critical path with useTransition (mark the update) or useDeferredValue (defer the value), and let React’s concurrent renderer keep your UI alive.