useTransition

what is useTransition ?

  • Profile picture of Mcs
  • by Mcs July 3, 2025

useTransition() is a React Hook that helps you mark state updates as “non-urgent” so the UI stays responsive — even during slow renders.

useTransition() is a React hook introduced in React 18 that allows you to mark certain state updates as "non-urgent" or "transitions." This is particularly useful for improving the responsiveness of your application's user interface during computationally intensive or potentially slow updates.

Why Use useTransition()?

In React apps:

  1. Some updates (like typing) are urgent
  2. Others (like rendering a huge filtered list) are non-urgent
  3. useTransition() lets you prioritize updates:
  4. Keep fast things like input typing responsive
  5. Delay heavy things like filtering, sorting, or rendering large data

Syntax

const [isPending, startTransition] = useTransition();

  1. startTransition(callback) → Runs non-urgent updates
  2. isPending → Boolean flag that’s true while the update is in progress

Simple Example: Search List

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

function FilteredList({ query }) {
 const items = Array(20000)
   .fill(0)
   .map((_, i) => `Item ${i}`)
   .filter(item => item.includes(query));

 return items.map(item => <div key={item}>{item}</div>);
}

function App() {
 const [input, setInput] = useState('');
 const [search, setSearch] = useState('');
 const [isPending, startTransition] = useTransition();

 const handleChange = (e) => {
   const value = e.target.value;
   setInput(value); // urgent

   startTransition(() => {
     setSearch(value); // non-urgent
   });
 };

 return (
   <>
     <input
       type="text"
       value={input}
       onChange={handleChange}
       placeholder="Search..."
     />
     {isPending && <p>Loading...</p>}
     <FilteredList query={search} />
   </>
 );
}

The input stays responsive while filtering happens in the background.

Benefits of useTransition()

FeatureWhat it Does
startTransition()Marks updates as low-priority
isPendingIndicates if the transition is still running
Prevents blockingKeeps urgent UI (like typing) fast
Ideal forSearch filters, lazy loading, tab switches

Important Notes

  1. It’s used for state updates only, not side effects
  2. Doesn’t work with DOM operations like useLayoutEffect or ref access
  3. Only available in React 18+

Summary

HookDescription
useTransition()Defers expensive state updates to keep UI responsive
startTransition()Wraps slow update (e.g., filtering large data)
isPendingShows loading or fallback state during that update

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.