Transitions

Mark updates as non-urgent so the UI stays responsive.

Builds on Rendering and scheduling.

The last chapter ended on an uncomfortable fact: React's rendering is concurrent, but a keystroke's update is urgent and renders to completion, slow components and all. Concurrency is something you opt into per update. This chapter is about the opt-in. A transition is an update you've marked as non-urgent, which puts it in a lane React can interrupt, restart and render in slices while the urgent stuff (your typing) stays instant.

We'll use the reading list as the running example: a search box over the books, where each row is deliberately slow to render.

The problem: a search box that can't keep up#

Each BookRow below burns 25 ms (imagine it draws a cover, a rating and a reading-progress chart). Ten of them cost about 250 ms. Leave Use a transition unchecked and type "systems" quickly into the search box.

Reading list search, with and without a transition
import { useState, useTransition } from "react";
import { books, slowDown } from "guide-tools";

function BookRow({ title, author }: { title: string; author: string }) {
  slowDown(25); // cover, rating, progress chart...
  return (
    <li>
      <strong>{title}</strong> <span style={{ color: "#78716c" }}>by {author}</span>
    </li>
  );
}

function BookList({ query }: { query: string }) {
  const q = query.toLowerCase();
  const visible = books.filter((b) => (b.title + " " + b.author + " " + b.tags.join(" ")).toLowerCase().includes(q));
  return (
    <ul>
      {visible.map((b) => (
        <BookRow key={b.id} title={b.title} author={b.author} />
      ))}
    </ul>
  );
}

function SearchBox({ useTx, onSearch }: { useTx: boolean; onSearch: (q: string) => void }) {
  const [text, setText] = useState("");
  const [isPending, startTransition] = useTransition();

  function handleChange(value: string) {
    setText(value); // urgent: the input must show the keystroke now
    if (useTx) {
      startTransition(() => onSearch(value)); // non-urgent: the list can lag
    } else {
      onSearch(value);
    }
  }

  return (
    <p>
      <input placeholder="Search books" value={text} onChange={(e) => handleChange(e.target.value)} />{" "}
      {isPending ? <span style={{ color: "#a0461f" }}>Updating...</span> : null}
    </p>
  );
}

export default function App() {
  const [useTx, setUseTx] = useState(false);
  const [query, setQuery] = useState("");
  return (
    <>
      <label>
        <input type="checkbox" checked={useTx} onChange={(e) => setUseTx(e.target.checked)} /> Use a transition
      </label>
      <SearchBox key={String(useTx)} useTx={useTx} onSearch={setQuery} />
      <BookList query={query} />
    </>
  );
}

Without the transition, characters appear in clumps. Each keystroke's render includes the whole list, and the next keystroke can't even be processed until that render is done. Now tick the box and type again. The input keeps up with you, "Updating..." appears, and the list catches up when you pause. Same components, same 250 ms of work. The only difference is that the list update was marked as a transition.

What a transition actually changes#

A transition doesn't make any render faster. It changes three things about when and how React does the work:

  1. Priority. The update goes into a transition lane, below every urgent lane. If a keystroke arrives, React handles the keystroke first.
  2. Interruptibility. Transition renders run in the time-sliced loop. React renders fibers for about 5 ms, then yields to the browser so it can handle input and paint, and then picks the most urgent pending work. If a newer update arrives, the half-built tree is thrown away and the render restarts from the latest state.
  3. What the user sees while it's pending. React keeps showing the current UI until the transition's render is complete and commits. Nothing in between ever appears. (This also matters for Suspense: a transition won't replace already visible content with a loading fallback. More on that in the Suspense chapter.)
One main thread, two kinds of work
UrgentTransitiontime →abrender 'a': input + 200 rowsrender 'ab': input + 200 rows'b' waits until the whole first render is done
Step 1 of 4

Without a transition. Each keystroke is an urgent update, and its render includes all 200 slow rows. The second keystroke can't even be handled until the first render finishes, so the input visibly lags.

One consequence is worth saying out loud: time slicing works between fibers, not inside one. React can yield between BookRows, but it can't pause in the middle of a single component's function. A single component that does 250 ms of work in one call would still block for 250 ms, transition or not. Splitting expensive UI into components is what gives the scheduler places to stop.

Why the code is split the way it is#

Look at where the state lives in that sandbox. SearchBox owns text (urgent) and calls useTransition. App owns query (the transition). That split is deliberate and comes straight from the previous chapter.

  • An input's value has to be urgent state. A controlled <input> must be updated synchronously within the event, or React restores its old value and keystrokes get lost. The docs say it flatly: transition updates can't be used to control text inputs.
  • isPending is state of the component that called useTransition. When you call startTransition, React schedules an urgent render of that component with isPending: true. If that component were App, the urgent render would re-render the slow list with the old query, and you'd be back to blocking. Keeping useTransition in the cheap SearchBox keeps the urgent work small.

So: urgent state close to the input, transition state above the expensive part, and the pending flag wherever it's cheap to re-render.

The API#

useTransition and startTransition React 18#

const [isPending, startTransition] = useTransition();

startTransition(() => {
  setQuery(value); // every setter called synchronously in here is a transition
});
  • startTransition calls your function immediately and marks every state update scheduled while it runs as a transition. It doesn't delay anything by itself.
  • Updates scheduled later, in a setTimeout callback for example, are not marked. The function only marks what happens during its synchronous execution (with one async exception, covered next).
  • isPending turns true as soon as you start the transition and stays true until the transition's result is on screen.
  • The startTransition function has a stable identity, so it's safe in dependency arrays and fine to omit.

There's also a standalone startTransition you import from react. Use it outside components, for example in a router or a data library. It has no isPending, and errors thrown in it can't be caught by an error boundary (there's no component to attach them to).

You can only wrap a setter call in a transition. If the value you want to treat as non-urgent arrives as a prop, or comes out of a hook you don't control, you can't reach its setter. That's what the next hook is for.

useDeferredValue React 18#

useDeferredValue(value) gives you a copy of a value that's allowed to lag behind. On each update, React first renders with the old deferred value (urgent and cheap), then starts a background render with the new value in a transition lane. If the value changes again first, the background render is abandoned and restarted.

The same search with useDeferredValue
import { memo, useDeferredValue, useState } from "react";
import { books, slowDown } from "guide-tools";

function BookRow({ title }: { title: string }) {
  slowDown(25);
  return <li>{title}</li>;
}

const BookList = memo(function BookList({ query }: { query: string }) {
  const q = query.toLowerCase();
  return (
    <ul>
      {books
        .filter((b) => b.title.toLowerCase().includes(q))
        .map((b) => (
          <BookRow key={b.id} title={b.title} />
        ))}
    </ul>
  );
});

export default function App() {
  const [text, setText] = useState("");
  const deferredText = useDeferredValue(text);
  const isStale = text !== deferredText;
  return (
    <>
      <input placeholder="Search books" value={text} onChange={(e) => setText(e.target.value)} />
      <div style={{ opacity: isStale ? 0.5 : 1, transition: "opacity 150ms" }}>
        <BookList query={deferredText} />
      </div>
    </>
  );
}

Two details make this work. First, BookList is wrapped in memo, which skips a render when the props are Object.is-equal to the last ones. During the urgent render deferredText hasn't changed, so the slow list is skipped. Without memo, the urgent render would re-render the list anyway (its parent rendered) and you'd gain nothing. The memoization chapter covers memo properly. Second, text !== deferredText is a free "stale" signal, the equivalent of isPending.

Pick between them like this: if you own the setter, useTransition is more direct and gives you isPending. If you're handed a value, useDeferredValue is the tool. useDeferredValue also takes an optional second argument, an initialValue for the first render, so the first paint can use something cheap and the real value fills in afterwards.

Async transitions React 19#

Since React 19 the function you pass to startTransition can be async. React tracks the returned promise, and isPending stays true across every await until the work finishes and its final state is on screen. A function used this way is what React calls an Action, and the next chapter builds forms on top of it.

Here's the reading list again, now searching through the fake API instead of filtering locally.

Searching the reading list through fakeFetch
import { useState, useTransition } from "react";
import { books, fakeFetch } from "guide-tools";

type Book = (typeof books)[number];

export default function App() {
  const [text, setText] = useState("");
  const [results, setResults] = useState<Book[]>(books);
  const [isPending, startTransition] = useTransition();

  function handleChange(value: string) {
    setText(value);
    startTransition(async () => {
      const data = await fakeFetch(`/books?q=${encodeURIComponent(value)}`, { delay: 600 });
      // After an await, wrap the setter again (see the note below).
      startTransition(() => {
        setResults(data as Book[]);
      });
    });
  }

  return (
    <>
      <input placeholder="Search books" value={text} onChange={(e) => handleChange(e.target.value)} />{" "}
      {isPending ? <span style={{ color: "#a0461f" }}>Searching...</span> : null}
      <ul style={{ opacity: isPending ? 0.6 : 1 }}>
        {results.map((b) => (
          <li key={b.id}>{b.title}</li>
        ))}
      </ul>
    </>
  );
}

Notice the inner startTransition after the await. React marks updates by setting a flag while your function runs synchronously. Once the function hits an await, the rest of it runs later in a fresh microtask, and JavaScript gives React no way to know that it still belongs to the same transition. A setter called there would be an ordinary default-priority update. The docs call this a known limitation they plan to fix (it needs something like async context in JavaScript). For now, wrap setters after an await in another startTransition.

Also notice what React doesn't do for you: ordering. If responses could come back out of order, an older request might finish last and overwrite newer results. Here every request takes the same 600 ms, so they don't. In real code, ignore stale responses (track the latest query, or abort the previous request with an AbortController), or let a data library handle it. useActionState, in the next chapter, queues its Actions so they run one after another.

Transitions render independently React 19.3#

What happens when two transitions are pending at once? Say a user clicks a tab that takes two seconds to render, and while it's still rendering, types into a search box that also updates in a transition.

// A slow tab switch...
startTransition(() => setTab("stats")); // renders a heavy chart page

// ...and, a moment later, an unrelated quick search.
startTransition(() => setQuery("systems"));

Up to React 19.2, pending transitions were entangled: React rendered them together as one batch, so the quick search couldn't commit until the slow tab switch was also ready. React 19.3 changed this. The changelog entry reads: React now renders transitions "independently instead of entangling them into a single render, so a slow Transition no longer holds up unrelated ones." In the example, the search results can commit while the stats page is still rendering in the background.

A few honest caveats. The changelog talks about unrelated transitions and doesn't document the edge cases, so don't build logic that depends on exactly how transitions touching the same state get grouped. And as of this writing, the useTransition reference page still carries its older caveat that multiple ongoing transitions are batched together; the 19.3 release notes are the newer source. In an interview, the useful version is: "since 19.3, a slow transition doesn't block an unrelated fast one."

Pitfalls#

Check your understanding#

Fix itThe search box eats characters

Someone "optimized" the reading list search by wrapping the input's setter in a transition. Now typing quickly loses characters. Fix it so typing works and the list still updates in a transition. The checks type "craft" and expect the input to say "craft" and the list to show only the matching books.

import { useState, useTransition } from "react";
import { books, slowDown } from "guide-tools";

function BookRow({ title }: { title: string }) {
  slowDown(10);
  return <li>{title}</li>;
}

export default function App() {
  const [query, setQuery] = useState("");
  const [isPending, startTransition] = useTransition();
  const visible = books.filter((b) => b.tags.join(" ").includes(query.toLowerCase()));

  return (
    <>
      <label>
        Tag{" "}
        <input
          value={query}
          onChange={(e) => {
            const value = e.target.value;
            startTransition(() => setQuery(value));
          }}
        />
      </label>
      {isPending ? <p>Updating...</p> : null}
      <ul>
        {visible.map((b) => (
          <BookRow key={b.id} title={b.title} />
        ))}
      </ul>
    </>
  );
}
PredictWhat's on screen while it's pending?

Stats takes about a second to render (it's many slow rows). The user is looking at the Shelf tab and clicks Stats. What do they see during that second, and what would change if selectTab called setTab(next) without startTransition?

function Tabs() {
  const [tab, setTab] = useState("shelf");
  const [isPending, startTransition] = useTransition();

  function selectTab(next: string) {
    startTransition(() => setTab(next));
  }

  return (
    <>
      <button onClick={() => selectTab("shelf")}>Shelf</button>
      <button onClick={() => selectTab("stats")} style={{ opacity: isPending ? 0.5 : 1 }}>
        Stats
      </button>
      {tab === "shelf" ? <Shelf /> : <Stats />}
    </>
  );
}
Quick checkPick the tool

A SearchResults component receives a query prop from a parent you can't change. Rendering the results is slow. What's the most direct way to keep typing responsive?

Quick checkAfter the await

Inside startTransition(async () => { const data = await load(); setItems(data); }), what priority does setItems get in React 19.3.1?

Explain it out loudTransitions versus debouncing

An interviewer asks: "What does useTransition do, and why not just debounce the input?"

Interview angle

Say it in 30 seconds

A transition marks a state update as non-urgent. React renders it in a lower-priority lane that's time-sliced: it yields between components, abandons and restarts the render if a newer update arrives, and keeps the current UI on screen until the new one is ready. useTransition gives you startTransition and an isPending flag; useDeferredValue does the same for a value you don't set. The input's own value stays urgent. Since React 19 transitions can be async, and since 19.3 a slow transition no longer holds up unrelated ones.

What is a transition in React?

basic

How is useTransition different from debouncing?

intermediate

When would you use useDeferredValue instead of useTransition?

intermediate

What happens if you put a controlled input's value update inside startTransition?

intermediate

How do async transitions work, and what's the catch with await?

senior

What changed about transitions in React 19.3?

senior

You wrapped a slow list update in startTransition but typing is still janky. What would you check?

senior

Recap#

  • A transition marks an update as non-urgent. React renders it in an interruptible lane, yields between fibers, restarts it when newer updates arrive and shows the old UI until it commits.
  • Keep a controlled input's value urgent. Transition the expensive consequence, and keep useTransition in a cheap component because isPending changes with an urgent render.
  • useDeferredValue defers a value you don't set. It needs a memoized child to pay off, and it isn't a debounce.
  • Since React 19, startTransition accepts async functions and isPending spans the awaits. Setters after an await must be wrapped in startTransition again.
  • Since 19.3, transitions render independently, so a slow transition no longer holds up an unrelated one.

Sources#