Transitions and deferred values

Topic 3 of 4 in Performance7 min readIntermediateFree course

Overview

Sometimes an update is unavoidably expensive: filtering and rendering thousands of rows, drawing a complex chart, switching to a heavy tab. React normally renders updates synchronously and to completion, so while that work runs, the browser can’t respond to the next keystroke — typing stutters and clicks feel ignored.

React’s concurrent features fix this by letting you mark some updates as non-urgent. React works on them in the background, and drops or restarts them when something more urgent happens.

Without a transition, typing “r” triggers a 5,000-result render that blocks typing, so “re” and “rea” appear late. With startTransition, typing “r”, “re” and “rea” is handled immediately; the list renders for “r” and “re” are interrupted and thrown away, and only the final list for “rea” completes. Code: const [isPending, startTransition] = useTransition(); startTransition(() => setFilter(text)), or const deferred = useDeferredValue(text).

Urgent and non-urgent updates

Think about what users expect:

  • Urgent: the text they type appears in the input; the checkbox they click ticks; the button they press looks pressed. These must happen instantly.
  • Non-urgent: the search results update; the next tab’s content appears; a chart redraws. A short delay is fine — as long as the urgent stuff isn’t blocked.

By default React treats every update as urgent. Transitions let you say “this one can wait”.

useTransition

Wrap a state update in startTransition to mark it as non-urgent:

JSX
import { useState, useTransition } from 'react';

function CourseTabs() {
  const [tab, setTab] = useState('overview');
  const [isPending, startTransition] = useTransition();

  function selectTab(nextTab) {
    startTransition(() => {
      setTab(nextTab);
    });
  }

  return (
    <>
      <TabButton isActive={tab === 'overview'} onClick={() => selectTab('overview')}>Overview</TabButton>
      <TabButton isActive={tab === 'lessons'} onClick={() => selectTab('lessons')}>Lessons</TabButton>
      <TabButton isActive={tab === 'reviews'} onClick={() => selectTab('reviews')}>Reviews</TabButton>
      {isPending && <Spinner size="small" />}

      <div style={{ opacity: isPending ? 0.7 : 1 }}>
        {tab === 'overview' && <Overview />}
        {tab === 'lessons' && <LessonsTab />}  {/* slow to render */}
        {tab === 'reviews' && <Reviews />}
      </div>
    </>
  );
}

Now, if the user clicks “Lessons” (slow) and then immediately “Reviews”, React abandons the half-finished Lessons render and switches to Reviews. Without the transition, the UI would freeze until Lessons finished.

  • isPending is true while the transition is in progress — use it for a subtle indicator.
  • During a transition, React keeps showing the old UI instead of hiding it behind a Suspense fallback.

Things to know about transitions

  • Text inputs can’t be controlled by a transition. The input’s own value must update urgently. Use two pieces of state — or useDeferredValue (below).
  • Transitions can be async. As you saw in Form actions, functions passed to startTransition can await; React keeps isPending true until they finish. State updates after an await need their own startTransition wrapper.
  • There’s a standalone startTransition (imported from react) for code outside components, without isPending.
  • Routers use transitions for navigation, which is why the old page stays visible while the next one loads.

useDeferredValue

When you don’t control the state update — for example, a value arrives as a prop — or when an input must stay urgent, use useDeferredValue:

JSX
import { memo, useDeferredValue, useState } from 'react';

function SearchPage() {
  const [query, setQuery] = useState('');
  const deferredQuery = useDeferredValue(query);
  const isStale = query !== deferredQuery;

  return (
    <>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <div style={{ opacity: isStale ? 0.5 : 1, transition: 'opacity 0.2s' }}>
        <SlowResults query={deferredQuery} />
      </div>
    </>
  );
}

const SlowResults = memo(function SlowResults({ query }) {
  // filters and renders thousands of items
});

What happens when the user types:

  1. React re-renders immediately with the new query but the old deferredQuery. The input updates instantly; SlowResults gets the same prop as before, and because it’s memoised, it’s skipped.
  2. Then React starts a background render with the new deferredQuery. If the user types again, this render is abandoned and restarted with the latest value.

Comparing query !== deferredQuery tells you the results are stale, so you can dim them.

memo matters here. If SlowResults re-rendered whenever its parent did, step 1 would still be slow. With React Compiler enabled, this happens automatically.

useDeferredValue with Suspense

If SlowResults fetches data with Suspense, the deferred value also stops the results flashing back to a loading fallback on each keystroke — the old results stay visible (dimmed) until the new ones are ready.

Debouncing vs deferring

You might reach for a debounce (wait 300 ms after typing stops). The difference:

Debounce useDeferredValue
Delay fixed, even on fast devices none — renders as soon as the device can
Interruptible no — once a render starts, it blocks yes — abandoned if the user types again
Good for limiting network requests keeping rendering responsive

They solve different problems and work well together: defer rendering, debounce fetching.

When to use which

Situation Tool
You trigger the update (tab click, filter change) useTransition
You need a pending flag useTransition
A value comes from props or from an input that must stay urgent useDeferredValue
Rendering is always slow, even once optimise the component, or virtualise the list

Transitions don’t make work faster — they make it interruptible. If a render takes 2 seconds, it still takes 2 seconds; the difference is that the user can keep typing and clicking meanwhile.

Exercise

A responsive course search

SlowResults({ query }) renders 2,000 items and is deliberately slow. Build SearchPage so that typing in the input stays instant: use useDeferredValue to pass a deferred query to the (memoised) results, and dim the results to 50% opacity while they’re stale (when query !== deferredQuery). Then add tabs (“All”, “Beginner”, “Advanced”) that switch with useTransition, showing “Loading…” next to the tabs while the transition is pending.

JavaScript
import { memo, useDeferredValue, useState, useTransition } from 'react';

const SlowResults = memo(function SlowResults({ query, level }) {
  // provided: renders 2,000 filtered items slowly
});

export function SearchPage() {
  // your code here
}

Summary

  • Urgent updates (typing, clicking) need instant feedback; non-urgent ones (big list renders) can wait.
  • startTransition(() => setState(…)) marks an update as non-urgent; React can interrupt it to handle typing.
  • useTransition() adds an isPending flag for showing that a transition is in progress.
  • useDeferredValue(value) gives you a version of a value that lags behind during heavy renders.
  • The slow component must be memoised (or compiled) so it only re-renders when the deferred value changes.