Concurrent Rendering and Interruptible Work
Build, explain and debug React 19 interfaces: components, rendering, state, effects, identity, forms and actions, server components, concurrency, performance and testing, ending with architecture and typing work on real component challenges.
What you will be able to do
#- Explain how concurrent rendering makes work interruptible.
- Keep urgent updates responsive with transitions and deferred values.
- Explain why render purity is required for interruptible rendering.
Overview
#Rendering can be interrupted
Concurrent rendering lets React pause, resume or abandon a render so that urgent updates stay responsive. In the default synchronous model a render runs to completion; with concurrent features React can work on a non-urgent render in the background and drop it if something more urgent arrives.
Transitions mark non-urgent updates
A transition tells React that a state update can be interrupted. Urgent updates, such as typing, are applied immediately; the transition update happens when React is free.
const [isPending, startTransition] = useTransition();
function onChange(e) {
setQuery(e.target.value);
startTransition(() => setFilter(e.target.value));
}
useDeferredValue defers a value
useDeferredValue returns a copy of a value that lags behind during heavy renders. It is the tool when you receive a value you cannot wrap in a transition.
const deferred = useDeferredValue(query);
const results = useMemo(() => search(deferred), [deferred]);
Consistency and tearing
Concurrent rendering must not show two different values of the same state in one frame. React guarantees that a commit reflects a single consistent state. External stores must integrate through useSyncExternalStore so React can detect changes and avoid tearing.
No timing guarantee
Concurrency is about responsiveness, not speed. React may render a transition immediately or delay it; it may abandon and restart. Do not rely on a transition completing within a fixed time.
Pitfall: side effects in render
Because a render can be abandoned or repeated, render must be pure. Side effects in render can run multiple times or for work that is thrown away. Keep effects in useEffect and handlers.
Pitfall: mixing urgent and non-urgent state carelessly
If a transition updates state that an urgent update also reads, the UI can briefly show inconsistent combinations. Group related updates so they transition together.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
A transition is running and the user types again. What happens?
Read the code, then choose the best answer. The reference explanation stays hidden until you respond. stimulus.tsxstartTransition(() => setFilter(value));Exercise 2Implement
Keep a search input responsive while filtering a large list, using useDeferredValue.
starter.tsxfunction Search({ items }: { items: Item[] }) { const [query, setQuery] = useState(''); return <input value={query} onChange={(e) => setQuery(e.target.value)} />; }Reveal the reference answer
reference.tsximport { useDeferredValue, useMemo } from 'react'; function Search({ items }: { items: Item[] }) { const [query, setQuery] = useState(''); const deferred = useDeferredValue(query); const results = useMemo(() => items.filter((i) => i.label.includes(deferred)), [items, deferred]); return ( <> <input value={query} onChange={(e) => setQuery(e.target.value)} /> <ul>{results.map((r) => <li key={r.id}>{r.label}</li>)}</ul> </> ); }Authored expected output: Typing stays responsive; the filtered list catches up when React is free.
The input uses the urgent query value, while the expensive filter uses the deferred copy. React can render the input immediately and defer the list work.
Exercise 3Debug
This component sometimes logs twice for one interaction. Explain why and fix.
starter.tsxfunction List({ items }: { items: Item[] }) { console.log('rendering', items.length); saveAnalytics(items.length); return <ul>{items.map((i) => <li key={i.id}>{i.label}</li>)}</ul>; }Reveal the reference answer
reference.tsxfunction List({ items }: { items: Item[] }) { console.log('rendering', items.length); useEffect(() => { saveAnalytics(items.length); }, [items.length]); return <ul>{items.map((i) => <li key={i.id}>{i.label}</li>)}</ul>; }Authored expected output: Analytics is recorded once per committed change, not on discarded renders.
A concurrent render can be started, interrupted and restarted, so a side effect in render can run more than once or for work that is thrown away. Moving it into an effect ties it to committed renders.
Exercise 4Interview
Explain concurrent rendering and why render purity becomes even more important with it.
starter.tsx// interruptible render, transitions, purityReveal the reference answer
reference.tsxConcurrent rendering lets React pause, resume or abandon a render so urgent updates stay responsive. Transitions and useDeferredValue mark non-urgent work that can be interrupted. Because a render may be started, thrown away and restarted, render must be pure: no mutation of outside values, no side effects, no reliance on how many times it runs. Side effects belong in effects or event handlers, where they run once per commit or per interaction. This is why StrictMode double-invocation and concurrent rendering both surface impurity.Authored expected output: A written explanation of interruptibility plus the purity requirement it imposes.
The connection is that interruptibility means render is not a once-only function. Purity is what makes repeating or discarding a render safe.
Common misconceptions
#- Concurrent rendering makes the app faster. It keeps the UI responsive by making renders interruptible; total work is similar.
- A transition always completes quickly. React may delay, restart or abandon it.
- Concurrency allows side effects in render. Render can repeat or be discarded, so it must stay pure.
- useDeferredValue waits a fixed time. It lags under load, not by a timer.
Follow-up practice
#- react-profiling-and-devtools
- react-external-stores
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.