useTransition is a hook that allows marking an update as "less urgent" so React does not block the interface.
Simple analogy: Imagine you are driving a car and simultaneously looking at the navigator.
How it works:
1import { useState, useTransition } from 'react';23function SearchPage() {4 const [query, setQuery] = useState('');5 const [results, setResults] = useState([]);6 const [isPending, startTransition] = useTransition();78 function handleChange(e) {9 const value = e.target.value;10 setQuery(value); // URGENT: update input1112 startTransition(() => {13 const filtered = bigList.filter(item =>14 item.name.includes(value)15 );16 setResults(filtered); // NOT URGENT: can wait17 });18 }1920 return (21 <>22 <input value={query} onChange={handleChange} />23 {isPending && <Spinner />} {/* While filtering — show spinner */}24 <ResultsList items={results} />25 </>26 );27}
When to use:
useTransition returns [isPending, startTransition]. isPending is true while the deferred update is executing.