Mark non-urgent work with transitions
Choose which work can wait
A transition marks a React state update as less urgent than immediate interaction. For example, typing a search term should update its input promptly while rendering a long result list can take lower priority. useTransition supplies a pending flag and a function for marking updates. The callback runs immediately; React can interrupt the associated rendering work. These are standalone client App.jsx examples using React 18+ unless noted. Expected visual results are predictions, not browser test results.
import React,{useState,useTransition,startTransition,useDeferredValue,memo,Profiler} from 'react';const records=Array.from({length:600},(_,i)=>({id:i+1,name:`${i%2===0?'Cedar':'Birch'} sample ${i+1}`}));function searchRecords(query,items=records){const term=query.trim().toLowerCase();return items.filter(item=>item.name.toLowerCase().includes(term));}function moveIndex(index,delta,length){return Math.max(0,Math.min(length-1,index+delta));}const Results=memo(function Results({query}){ const matches=searchRecords(query); return <section><p>{matches.length} matches</p><ul>{matches.map(item=><li key={item.id}>{item.name}</li>)}</ul></section>;});export default function App(){ const [text,setText]=useState('');const [query,setQuery]=useState(''); const [isPending,runTransition]=useTransition(); function change(e){const next=e.target.value;setText(next);runTransition(()=>setQuery(next));} return <section><label>Search samples <input value={text} onChange={change}/></label> <p role="status">{isPending?'Updating results':'Results ready'}</p><div aria-busy={isPending}><Results query={query}/></div></section>;}Initially all 600 records are listed. Typing cedar eventually shows 300 records. The input reads text, never query. The memoized list can reuse previous work when its query has not changed. The separate query is intentional because it represents a lower-priority rendering request, not a second independently editable field. Pending feedback may be too brief to notice on a fast device. Do not expect a specific sequence or number of renders.
Mark updates without a pending indicator
import React,{useState,useTransition,startTransition,useDeferredValue,memo,Profiler} from 'react';function Results({kind}){return <p>Showing {kind} samples</p>;}export default function App(){const [kind,setKind]=useState('Cedar'); return <section><button onClick={()=>startTransition(()=>setKind('Cedar'))}>Cedar</button><button onClick={()=>startTransition(()=>setKind('Birch'))}>Birch</button><Results kind={kind}/></section>;}Selecting Birch changes the displayed category. The standalone function can be used outside a Hook when the caller owns the state setter, but does not expose a pending flag. It does not delay a callback, move CPU work to another thread, or make arbitrary synchronous calculation interruptible. Keep expensive computation out of event handlers. A single long synchronous function can still block the browser; reduce or partition work or use a Worker when appropriate.
Handle an asynchronous Action explicitly
import React,{useState,useTransition,startTransition,useDeferredValue,memo,Profiler} from 'react';const loadLabel=()=>new Promise(resolve=>setTimeout(()=>resolve('300 cedar samples'),150));export default function App(){const [label,setLabel]=useState('Not loaded');const [isPending,runTransition]=useTransition(); function load(){runTransition(async()=>{const result=await loadLabel();runTransition(()=>setLabel(result));});} return <section><button disabled={isPending} onClick={load}>Load sample count</button><p role="status">{isPending?'Loading count':label}</p></section>;}The local timer resolves once with a fixed result and cannot reject. On the React 19 Action baseline, the outer asynchronous transition tracks pending work; the inner call explicitly marks the setter after await. React 18 should use separate loading state and mark the eventual update instead. A real request needs error handling, cancellation or stale-response protection, and an ordering policy; transitions do not supply those automatically. This single-operation example prevents ordinary repeated clicks while pending. Practice: identify which setters must be urgent and explain why putting a long loop inside startTransition would still block interaction.