Hackforge Academy

Category: react

What Is useTransition?

Published on 27 Oct 2026

Explanation

useTransition lets you mark certain state updates as non-urgent. React can keep urgent interactions responsive while working on a slower UI update.

Code:

const [isPending, startTransition] = useTransition();

function selectTab(tab) {
  startTransition(() => {
    setSelectedTab(tab);
  });
}

Explanation

Input state should usually update urgently, while rendering a large result panel can be marked as a transition. This helps React prioritize the user's typing.

Code:

const [query, setQuery] = useState('');
const [filter, setFilter] = useState('');
const [isPending, startTransition] = useTransition();

function handleChange(event) {
  const value = event.target.value;
  setQuery(value);
  startTransition(() => setFilter(value));
}

Explanation

The isPending value tells you when transition work is pending. Use it to provide lightweight feedback while the non-urgent update is being prepared.

Code:

const [isPending, startTransition] = useTransition();

return (
  <>
    <button onClick={() => startTransition(() => setTab('reports'))}>
      Reports
    </button>
    {isPending && <span>Loading view...</span>}
  </>
);

Explanation

A transition marks state updates as non-urgent; it does not automatically make network requests faster or replace data-fetching logic. Handle request status and errors separately.

Code:

async function saveProfile() {
  setSaving(true);
  try {
    await fetch('/api/profile', { method: 'POST' });
  } finally {
    setSaving(false);
  }
}

Explanation

Use transitions for updates that can wait briefly, such as switching a complex view or rendering filtered results. Do not mark controlled text-input updates themselves as transitions.

Code:

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

  function openReports() {
    startTransition(() => setTab('reports'));
  }

  return <button onClick={openReports} disabled={isPending}>Reports</button>;
}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community