Skip to content

QuizNot attempted

Deferring an expensive child

What is the primary benefit of using deferredText (instead of text directly) as the prop to ExpensiveList?
function SearchResults() {
const [text, setText] = useState('');
const deferredText = useDeferredValue(text);
return (
<>
<input value={text} onChange={e => setText(e.target.value)} />
<ExpensiveList text={deferredText} />
</>
);
}
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • It keeps the <input> responsive to typing by letting the expensive list's re-render lag behind and be interrupted, rather than blocking the keystroke-driven update
  • Passing deferredText lets React render the input's urgent update first and re-render ExpensiveList in a lower-priority, interruptible pass, so typing stays responsive (wrap ExpensiveList in memo so the urgent render can skip it).
  • Not 'never re-renders': it re-renders, just later.
  • Not caching outputs: that is memo/useMemo.
  • Not a Server Component: hooks can't change where a component runs.