ReactMedium

What is useTransition?

useTransition() returns [isPending, startTransition]. Wrapping a state update in startTransition marks it as non-urgent, so React keeps the UI responsive: urgent updates like typing and clicks interrupt it, the old UI stays on screen instead of showing Suspense fallbacks, and isPending lets you show a subtle loading indicator.

What transitions do

  • Interruptible rendering: if the user types again, React abandons the in-progress render and starts over with the latest value.
  • No unwanted fallbacks: when a transition causes a component to suspend, React keeps showing the previous content.
  • Async functions (React 19): startTransition(async () => { await save(); setX(...) }) is an Action; isPending stays true until it finishes, and errors bubble to error boundaries.
  • Independent rendering (React 19.3): separate transitions no longer block each other.

Typical uses

  • Switching tabs that render heavy content.
  • Filtering a large list (combined with an urgent update for the input itself).
  • Navigation in routers (React Router and Next.js wrap navigations in transitions).
  • Form submissions and mutations (Actions).

Rules

  • The function you pass runs synchronously; state updates inside it (and after await in React 19) are marked as transitions. If you set state after an await in an older pattern, wrap that update in another startTransition.
  • Controlled input values must not be updated inside a transition, or typing lags.
  • There is a standalone startTransition import for use outside components (no isPending).

Related

useDeferredValue defers a value instead of an update. addTransitionType (stable in React 19.3) labels transitions for <ViewTransition> animations.

Code example

tsx
1import { useState, useTransition } from "react";
2
3function HeavyList({ filter }: { filter: string }) {
4 const items = Array.from({ length: 20_000 }, (_, i) => `Item ${i}`);
5 return <ul>{items.filter((i) => i.includes(filter)).slice(0, 200).map((i) => <li key={i}>{i}</li>)}</ul>;
6}
7
8export function FilterableList() {
9 const [text, setText] = useState("");
10 const [filter, setFilter] = useState("");
11 const [isPending, startTransition] = useTransition();
12
13 return (
14 <div>
15 <input
16 value={text}
17 onChange={(e) => {
18 setText(e.target.value); // urgent: input stays responsive
19 startTransition(() => setFilter(e.target.value)); // non-urgent: can be interrupted
20 }}
21 />
22 <div style={{ opacity: isPending ? 0.5 : 1 }}>
23 <HeavyList filter={filter} />
24 </div>
25 </div>
26 );
27}
28
29// React 19 Action: async transition with pending state
30// const [saving, start] = useTransition();
31// <button disabled={saving} onClick={() => start(async () => { await saveDraft(text); })}>Save</button>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app