Course contentsShow
← React
Lesson 2305 of 2,39650. Performance: Optimization TechniquesFree lesson

Deferring vs Debouncing: When Each Fits

Compare useTransition's render-priority approach with traditional debouncing, and understand when each technique is appropriate.

Deferring vs Debouncing: When Each Fits

You'll learn: When to use useTransition (deferring) versus traditional debouncing, and why each technique solves different performance problems.

Two Approaches, Different Goals

Both deferring (with useTransition) and debouncing reduce work during rapid user input, but they work differently:

  • Debouncing delays executing a function until the user stops typing for a set period (e.g., 300ms). It prevents unnecessary work by batching multiple inputs into one delayed action.
  • Deferring (via useTransition) prioritizes updates. It lets urgent updates (like typing) render immediately while marking expensive updates (like filtering a list) as non-urgent. React renders both, but keeps the UI responsive.

When Debouncing Fits

Use debouncing when:

  • You want to reduce network requests (API calls, autocomplete)
  • The expensive operation shouldn't happen until input stabilizes
  • You're okay with a delay before showing results
const [query, setQuery] = useState('');

const debouncedSearch = useMemo(
  () => debounce((value) => fetchResults(value), 300),
  []
);

When Deferring Fits

Use useTransition when:

  • The expensive work is rendering (not network/external)
  • You want instant visual feedback while processing happens
  • You need responsive input even during heavy updates
const [isPending, startTransition] = useTransition();

const handleChange = (e) => {
  setValue(e.target.value); // Urgent: instant feedback
  startTransition(() => {
    setFilteredList(expensiveFilter(e.target.value)); // Deferred
  });
};

The Key Difference

Debouncing says "wait, don't do it yet." Deferring says "do it now, but don't block the UI."

Key Takeaway: Use debouncing to skip work by waiting for input to settle; use useTransition to prioritize work while keeping the UI responsive during rendering.