Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.
Exercise 1 of 2
Four questions on useTransition — urgent vs deferred updates, isPending semantics, what startTransition does NOT do, and when to reach for it.
const [isPending, startTransition] = useTransition();
function handleSearch(e) {
const val = e.target.value;
setInputValue(val); // line A
startTransition(() => {
setFilteredList( // line B
bigList.filter(item => item.includes(val))
);
});
}Which update is urgent and which is deferred?
What does isPending === true mean?
What does startTransition NOT do?
useTransition is most appropriate when…
0/4 answered
Exercise 2 of 2
Live editor: a search input lags because every keystroke triggers an expensive list render. Add useTransition to decouple input responsiveness from list rendering.
Task
The input lags — every keystroke triggers a 50ms render of SlowList. Type quickly and feel the delay.
Fix it with useTransition:
inputValue (urgent) and query (deferred)inputValue immediately — this keeps the input responsivesetQuery call in startTransitionisPending to show a "Filtering…" message