---
title: "useTransition and useDeferredValue – React Hooks"
url: https://www.khanwaseem.com/blog/react-tutorial/react-usetransition-and-usedeferredvalue
author: "khan Waseem"
published: 2026-11-29
updated: 2026-11-29
topics: ["React Tutorial", "course"]
description: "Keep your React app responsive during heavy updates. Learn useTransition and useDeferredValue with tested React 19 examples: a laggy search fixed with a deferred value, tabs that stay clickable, async actions with…"
---

# useTransition and useDeferredValue – React Hooks

Table of Contents

[Toggle](#)

- [Introduction:](#introduction)
- [Part 1: The Problem](#part-1-the-problem)[1. Urgent vs Non-Urgent Updates:](#1-urgent-vs-non-urgent-updates)
- [2. A Slow Search List:](#2-a-slow-search-list)

- [Part 2: useDeferredValue](#part-2-usedeferredvalue)[3. Fixing the Search with useDeferredValue:](#3-fixing-the-search-with-usedeferredvalue)
- [4. Showing That Content Is Stale:](#4-showing-that-content-is-stale)
- [5. The initialValue Option (React 19):](#5-the-initialvalue-option-react-19)

- [Part 3: useTransition](#part-3-usetransition)[6. Basic Syntax:](#6-basic-syntax)
- [7. Tabs That Stay Clickable:](#7-tabs-that-stay-clickable)
- [8. Async Actions in Transitions (React 19):](#8-async-actions-in-transitions-react-19)
- [9. startTransition Without the Hook:](#9-starttransition-without-the-hook)

- [Part 4: Choosing the Right Hook](#part-4-choosing-the-right-hook)[10. useTransition vs useDeferredValue:](#10-usetransition-vs-usedeferredvalue)
- [11. Why Not Debounce?:](#11-why-not-debounce)
- [12. Common Mistakes:](#12-common-mistakes)

- [Conclusion:](#conclusion)

## Introduction:

Have you ever typed into a search box and felt the letters appear late, as if the keyboard were stuck? Or clicked a tab and watched the whole page freeze for a moment before anything happened? In React, this usually happens when one small update (a keystroke or a click) causes a **big, slow re-render**, such as filtering a long list or drawing a heavy chart.

By default, React treats every state update as equally **urgent**. While it is busy re-rendering 5,000 list items, it cannot do anything else, including showing the letter you just typed.

React 18 introduced **concurrent rendering**, and with it two hooks that let you tell React which updates are urgent and which can wait:

- **useTransition** marks a state update as **non-urgent** (a “transition”).

- **useDeferredValue** gives you a **lagging copy** of a value that can update a little later.

React 19 made transitions even more useful by allowing **async functions** inside them. In this lesson we will see the problem in action, fix it with both hooks, and learn exactly when to use which. It builds on [useState](https://blog.khanwaseem.com/usestate/), [useMemo](https://blog.khanwaseem.com/usememo-hook-react/) and the [Optimizing Performance](https://blog.khanwaseem.com/performance/) lesson.

All examples were run with **React 19.3** in a real Chromium browser, and the measurements in the comments are the real results.

## Part 1: The Problem

### 1. Urgent vs Non-Urgent Updates:

Think of a restaurant. When a customer asks for the bill, the waiter should respond **right away**. Cleaning the tables can wait a few seconds. If the waiter insisted on cleaning every table before answering anyone, customers would feel ignored, even though the waiter is working hard.

React updates are similar:

- **Urgent updates** respond directly to the user: typing, clicking, pressing a key. If they are slow, the app feels broken.

- **Non-urgent updates** show the *result* of that action: a filtered list, a new tab’s content, a chart. A short delay is fine, as long as the app stays responsive.

Without any hints, React handles both in one go, so the slow part blocks the fast part.

### 2. A Slow Search List:

Here is a search box that filters a list. To simulate a heavy component, each list item deliberately wastes 1 ms when it renders, so the list of 250 items takes about a quarter of a second:

```javascript
import { useState, memo } from "react";

function slow(ms) {
  const end = performance.now() + ms;
  while (performance.now() < end) {}   // simulate expensive work
}

function SlowItem({ text }) {
  slow(1);
  return <li>{text}</li>;
}

const SlowList = memo(function SlowList({ query }) {
  const items = [];
  for (let i = 0; i < 250; i++) {
    items.push(<SlowItem key={i} text={`${query} result ${i}`} />);
  }
  return <ul>{items}</ul>;
});

function Search() {
  const [query, setQuery] = useState("");
  return (
    <>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <SlowList query={query} />
    </>
  );
}Code language: JavaScript (javascript)
```

Every keystroke updates `query`, and React must re-render the whole slow list **before** it can show the new letter in the input.

In our test, typing the word `hello` (five keys, 30 ms apart) took **1,512 ms** to finish. The input could not keep up with the keyboard, because each letter waited for the list.

## Part 2: useDeferredValue

### 3. Fixing the Search with useDeferredValue:

`useDeferredValue` takes a value and returns a **deferred** version of it. On an urgent update, React first re-renders with the **old** deferred value (which is fast, because nothing changed for the slow list), and then tries to re-render with the new value **in the background**:

```javascript
import { useState, useDeferredValue } from "react";

function Search() {
  const [query, setQuery] = useState("");
  const deferredQuery = useDeferredValue(query);

  return (
    <>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <SlowList query={deferredQuery} />
    </>
  );
}Code language: JavaScript (javascript)
```

Only one line changed: the list now receives `deferredQuery` instead of `query`. The input still uses `query`, so it always shows exactly what you typed.

With this change, typing `hello` took **199 ms** instead of 1,512 ms. The letters appeared immediately, and the list caught up once typing paused.

Two details make this work:

- **The background render can be interrupted.** If you type another letter while React is rendering the list for the previous one, React throws that unfinished work away and starts again with the newest value. It never wastes time finishing a list nobody will see.

- **The slow component must be wrapped in `memo`.** During the urgent render, `SlowList` receives the same old `deferredQuery`, so `memo` lets React skip it completely. Without `memo`, the slow list would re-render during the urgent render too, and the benefit would disappear.

### 4. Showing That Content Is Stale:

While the list is catching up, it is showing results for an older query. You can detect this by comparing the two values, and give the user a hint:

```javascript
function Search() {
  const [query, setQuery] = useState("");
  const deferredQuery = useDeferredValue(query);
  const isStale = query !== deferredQuery;

  return (
    <>
      <input value={query} onChange={(e) => setQuery(e.target.value)} />
      <p>{isStale ? "Updating..." : "Up to date"}</p>
      <div style={{ opacity: isStale ? 0.5 : 1 }}>
        <SlowList query={deferredQuery} />
      </div>
    </>
  );
}Code language: JavaScript (javascript)
```

In our test, right after typing `ab` the screen showed:

```javascript
input:      "ab"
status:     "Updating..."
first item: " result 0"      // still the old (empty) queryCode language: JavaScript (javascript)
```

And a moment later:

```javascript
input:      "ab"
status:     "Up to date"
first item: "ab result 0"Code language: JavaScript (javascript)
```

Dimming the old results is a common pattern. The user sees that their input was received and that new results are on the way, instead of a frozen screen or a flashing spinner.

### 5. The initialValue Option (React 19):

React 19 added an optional second argument: the value to use on the **very first render**. This is useful when the real value is expensive, because the first paint can show something cheap and the real content follows right after:

```javascript
function Results() {
  const [query] = useState("react");
  const deferredQuery = useDeferredValue(query, "");
  console.log(`query=${query} deferred=${JSON.stringify(deferredQuery)}`);
  return <SlowList query={deferredQuery} />;
}

// Console (real output):
// query=react deferred=""
// query=react deferred="react"Code language: JavaScript (javascript)
```

The component rendered twice: first with the initial value `""`, then in the background with `"react"`. Without the second argument, the first render would use `"react"` directly.

## Part 3: useTransition

### 6. Basic Syntax:

`useTransition` works from the other side. Instead of deferring a **value**, you wrap the **state update** itself and mark it as non-urgent:

```javascript
const [isPending, startTransition] = useTransition();

startTransition(() => {
  setTab("posts");      // this update is a transition
});Code language: JavaScript (javascript)
```

It returns two things:

- **isPending:** `true` while the transition is still rendering. Use it to show a hint.

- **startTransition:** a function that runs your callback and marks every state update inside it as a transition.

### 7. Tabs That Stay Clickable:

Here is a classic example: three tabs, one of which (Posts) is slow to render:

```javascript
import { useState, useTransition } from "react";

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

  function select(next) {
    startTransition(() => {
      setTab(next);
    });
  }

  return (
    <>
      <button onClick={() => select("about")}>About</button>
      <button onClick={() => select("posts")}>Posts</button>
      <button onClick={() => select("contact")}>Contact</button>

      {isPending && <p>Loading...</p>}

      {tab === "about" && <About />}
      {tab === "posts" && <Posts />}      {/* 250 slow items */}
      {tab === "contact" && <Contact />}
    </>
  );
}Code language: JavaScript (javascript)
```

Our test clicked **Posts**, and then **Contact** before Posts had finished. This is what the browser showed:

```javascript
right after clicking Posts:    "Loading..." + the About page still visible
after clicking Contact:        no "Loading...", the Contact pageCode language: JavaScript (javascript)
```

Three useful things happened:

- The **old tab stayed on screen** while the new one rendered, instead of a blank page.

- **isPending** let us show “Loading…” straight away.

- The click on Contact **interrupted** the unfinished Posts render. Without a transition, the page would have frozen until Posts finished, and only then reacted to the second click.

### 8. Async Actions in Transitions (React 19):

In React 19, the function you pass to `startTransition` can be **async**. `isPending` stays `true` for the whole time, including while you wait for a network request. This replaces a lot of manual `isLoading` state:

```javascript
function fakeSave(name) {
  return new Promise((resolve) =>
    setTimeout(() => resolve(`Saved "${name}"`), 800)
  );
}

function SaveName() {
  const [name, setName] = useState("Zara");
  const [message, setMessage] = useState("");
  const [isPending, startTransition] = useTransition();

  function handleSave() {
    startTransition(async () => {
      const result = await fakeSave(name);
      startTransition(() => {
        setMessage(result);
      });
    });
  }

  return (
    <>
      <input value={name} onChange={(e) => setName(e.target.value)} />
      <button onClick={handleSave} disabled={isPending}>
        {isPending ? "Saving..." : "Save"}
      </button>
      <p>{message}</p>
    </>
  );
}

// 100 ms after clicking:  button "Saving..." (disabled), message ""
// after the save:         button "Save",                 message 'Saved "Zara"'Code language: JavaScript (javascript)
```

Notice the **second** `startTransition` around `setMessage`. Any state update that happens **after an `await`** is no longer inside the original transition, so React’s documentation recommends wrapping it again. This is a current limitation of how JavaScript tracks async code, and it may be removed in a future version of React.

React calls an async transition like this an **Action**. Newer hooks like `useActionState` and the `<form action={...}>` prop are built on the same idea, and we will cover them in a later lesson.

### 9. startTransition Without the Hook:

React also exports a plain `startTransition` function. It does the same thing but gives you no `isPending`. Use it outside components, for example in a data library or a router, or when you don’t need a pending indicator:

```javascript
import { startTransition } from "react";

function goToPage(page) {
  startTransition(() => {
    setPage(page);
  });
}Code language: JavaScript (javascript)
```

## Part 4: Choosing the Right Hook

### 10. useTransition vs useDeferredValue:

Both hooks do the same job underneath: they let React render something in the background, at lower priority, and interrupt it if something more urgent happens. The difference is **where you have control**:

- **useTransition** wraps the **state update**. Use it when you own the code that calls `setState`, such as a click handler.

- **useDeferredValue** wraps the **value**. Use it when you only receive the value, for example as a prop from a parent or from a library hook, and can’t change how it is set.

A quick way to decide:

- Clicking tabs, changing pages, submitting a form: **useTransition** (you also get `isPending`).

- A slow component that receives a fast-changing prop, like a search query or slider value: **useDeferredValue**.

### 11. Why Not Debounce?:

Before these hooks, the usual fix for a laggy search was **debouncing**: waiting, say, 300 ms after the last keystroke before updating the list. That works, but it has two problems:

- It always waits the full delay, even on a fast computer that could have shown results instantly.

- Once the slow render starts, it still blocks the page until it finishes.

`useDeferredValue` has **no fixed delay**. On a fast device, the list updates almost immediately; on a slow device, it falls behind gracefully, and it never blocks typing. Debouncing is still the right tool for limiting **network requests** (you don’t want an API call per keystroke), but for slow **rendering**, deferring is better.

### 12. Common Mistakes:

- **Using a transition for a controlled input.** `startTransition(() => setQuery(e.target.value))` on the input’s own state makes typing feel broken, because the input itself becomes non-urgent. Keep the input state urgent and defer the *slow part* instead, with `useDeferredValue` or with a second state updated in a transition.

- **Forgetting `memo`.** `useDeferredValue` only helps if the slow component can skip the urgent render. Wrap it in `memo` and make sure its props don’t change on every render (for example, a new object or function each time).

- **Expecting it to make code faster.** These hooks do not make a slow component faster. They make the **app stay responsive** while the slow work happens. If a component is very slow, also look at [useMemo](https://blog.khanwaseem.com/usememo-hook-react/), virtualised lists, or reducing the work itself.

- **Calling startTransition with a delay.** The callback must update state right away. `startTransition(() => setTimeout(() => setTab(t), 100))` does **not** mark the update as a transition, because it runs later, outside the callback.

- **Putting side effects inside.** The function passed to `startTransition` should only update state (and, in React 19, await async work). Don’t rely on it for logging or analytics timing.

## Conclusion:

React treats every update as urgent unless you say otherwise. **useTransition** lets you mark a state update as non-urgent, gives you an `isPending` flag, keeps the old screen visible while the new one renders, and in React 19 can wrap async work such as saving data. **useDeferredValue** gives a slow component a lagging copy of a fast-changing value, so typing stays smooth while results catch up.

In our tests, the same slow search went from **1,512 ms** to **199 ms** to type a five-letter word, just by deferring one value and wrapping the list in `memo`.

In the next lesson we will learn about **Error Boundaries**, which stop one broken component from crashing your whole React app.

### Related posts:

[React Redux](https://blog.khanwaseem.com/react-redux/)
[React State Management](https://blog.khanwaseem.com/react-state/)
[useState -React Hooks](https://blog.khanwaseem.com/usestate/)
[Forms and Controlled Components](https://blog.khanwaseem.com/forms-and-controlled-components/)

Powered by [YARPP](https://yarpp.com).
