Course contentsShow
← React
Lesson 1446 of 2,39636. Concurrent ReactFree lesson

Visual Feedback During Deferral

Detecting when a value is stale by comparing deferred and current values for loading states.

Visual Feedback During Deferral

You'll learn how to detect when a deferred value lags behind its current value, enabling accurate loading indicators.

The Problem with Silent Deferral

When you use useDeferredValue, React deliberately keeps the old (stale) value displayed while processing the new one. But here's the challenge: how do you show the user that an update is in progress?

Unlike useTransition, useDeferredValue doesn't give you an isPending flag. The solution? Compare the deferred value against the current value yourself.

Comparing Current and Deferred Values

function SearchResults({ query }) {
  const deferredQuery = useDeferredValue(query);
  const isStale = query !== deferredQuery;

  return (
    <div style={{ opacity: isStale ? 0.5 : 1 }}>
      <Results query={deferredQuery} />
    </div>
  );
}

When query changes, deferredQuery stays behind temporarily. During this window, isStale becomes true, letting you show visual feedback—dimmed content, a subtle spinner, or any other indicator.

Think of It Like a Photo Filter

Imagine applying a heavy photo filter. While the filter processes, you keep showing the original photo but add a translucent "Processing..." overlay. You know processing is happening because the photo you're displaying (deferred) doesn't match what the user selected (current).

That's exactly what comparing current and deferred values achieves: you detect the "processing window" by spotting the mismatch.

Common Visual Patterns

  • Opacity reduction: opacity: 0.6 during staleness
  • Subtle spinner: Small indicator in corner
  • Disabled interactions: Prevent clicks while stale
  • Border or background: Visual "busy" state

Key Takeaway: Detect stale deferred values by comparing them to current values—when they differ, your UI is mid-update and should show feedback to the user.