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;isPendingstays 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
awaitin React 19) are marked as transitions. If you set state after anawaitin an older pattern, wrap that update in anotherstartTransition. - Controlled input values must not be updated inside a transition, or typing lags.
- There is a standalone
startTransitionimport for use outside components (noisPending).
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";23function 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}78export function FilterableList() {9 const [text, setText] = useState("");10 const [filter, setFilter] = useState("");11 const [isPending, startTransition] = useTransition();1213 return (14 <div>15 <input16 value={text}17 onChange={(e) => {18 setText(e.target.value); // urgent: input stays responsive19 startTransition(() => setFilter(e.target.value)); // non-urgent: can be interrupted20 }}21 />22 <div style={{ opacity: isPending ? 0.5 : 1 }}>23 <HeavyList filter={filter} />24 </div>25 </div>26 );27}2829// React 19 Action: async transition with pending state30// 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.