useTransition
In one line
useTransition marks state updates as low priority so the UI stays responsive during heavy renders.
In simple words
useTransition (React 18) lets you distinguish urgent updates from non-urgent ones. Urgent updates (typing, clicking) should happen immediately. Non-urgent updates (filtering a large list, tab switching) can be deferred.
It returns [isPending, startTransition]. Wrap slow state updates in startTransition(). React keeps showing the current UI (responsive) while preparing the new one in the background. isPending lets you show a subtle loading indicator.
This is concurrent rendering — React can interrupt the transition if a more urgent update comes in.
Example
import { useState, useTransition } from "react";
function SearchBar({ items }) {
const [query, setQuery] = useState("");
const [isPending, startTransition] = useTransition();
const [filtered, setFiltered] = useState(items);
function handleChange(e) {
setQuery(e.target.value); // Urgent — update input immediately
startTransition(() => {
// Non-urgent — can be deferred
setFiltered(items.filter(i => i.includes(e.target.value)));
});
}
return (
<>
<input value={query} onChange={handleChange} />
{isPending && <span>Filtering...</span>}
<ul>{filtered.map(i => <li key={i}>{i}</li>)}</ul>
</>
);
}Input updates immediately (urgent). List filtering is wrapped in startTransition so typing stays smooth even with 10,000 items.
Common confusions
Confused with: useDeferredValue
The difference: useTransition wraps the state update function — you control when the transition starts. useDeferredValue wraps the value itself — React decides when to use the new vs old value. Use useTransition when you trigger the update, useDeferredValue when you receive a new value from props.
Related terms
Related Resources
Related Lessons
- React 18 Features
useTransition.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.