Non-blocking UI with useTransition in React
Master useTransition to keep your React UI responsive. Learn how to mark state updates as non-urgent to prioritize user input during heavy rendering.
Previously in this course, we explored Introduction to Concurrent React: Time-Slicing and Performance, which established how React's concurrent engine can pause and resume rendering work. In this lesson, we build on those fundamentals to exert explicit control over that process using useTransition.
When building complex dashboards or data-heavy interfaces, a single user action—like typing in a search bar—often triggers a massive re-render of a list or chart. If that render takes 200ms, the input field feels "stuck." useTransition is your primary tool to tell React, "This specific update is less important than the user typing; let the input stay responsive while you process the heavy update in the background."
Understanding Transitions from First Principles
In standard React, all state updates are considered "urgent." When you call setState, React enters a synchronous render phase to update the DOM. If the component tree is deep or the data transformation is complex, the main thread remains blocked until the work completes.
A transition is a specific category of state update that React treats as non-urgent. By wrapping a state setter in startTransition, you instruct React to:
- Interrupt: If a more urgent update (like a keystroke) comes in, pause the ongoing transition work.
- Defer: Keep the current UI interactive while the "transitioning" state is computed in the background.
- Commit: Once the background work is finished, apply the changes to the DOM.
Worked Example: Filtering Large Lists
Imagine a dashboard displaying a list of 5,000 items. Filtering this list on every keystroke usually creates noticeable input lag. Let's optimize this using useTransition.
TSXimport { useState, useTransition } from CE9178">'react'; function LargeListFilter({ items }) { const [query, setQuery] = useState(CE9178">''); const [filteredItems, setFilteredItems] = useState(items); const [isPending, startTransition] = useTransition(); const handleInputChange = (e) => { const value = e.target.value; // 1. Urgent: Update the input field immediately setQuery(value); // 2. Non-urgent: Filter the list in the background startTransition(() => { const nextFiltered = items.filter(item => item.name.toLowerCase().includes(value.toLowerCase()) ); setFilteredItems(nextFiltered); }); }; return ( <div> <input value={query} onChange={handleInputChange} placeholder="Filter items..." /> {isPending && <p>Updating list...</p>} <ul style={{ opacity: isPending ? 0.5 : 1 }}> {filteredItems.map(item => <li key={item.id}>{item.name}</li>)} </ul> </div> ); }
In this example, the setQuery call happens immediately, ensuring the input value stays in sync with the user's keystrokes. The setFilteredItems call is wrapped in startTransition, allowing React to prioritize the input update and process the list filter as a low-priority task. The isPending boolean provides a hook to give visual feedback, such as dimming the list or showing a spinner.
Managing Pending States
While isPending is useful, rely on it sparingly. Over-using loading indicators can lead to "UI flickering" if the transition finishes too quickly.
| Feature | Urgent State (setState) | Transition State (startTransition) |
|---|---|---|
| Priority | High (Immediate) | Low (Background) |
| User Input | Blocked until finish | Interrupted by input |
| Use Case | Typing, Toggling, Selecting | Filtering, Sorting, Data Views |
Hands-on Exercise
Refactor an existing search component in your project:
- Introduce
useTransitionto your search input handler. - Observe the render count in the React DevTools Profiler (as taught in Profiling with React DevTools: Identifying Performance Bottlenecks).
- Add a visual indicator (like a CSS class or
isPendingflag) to signify that the list is stale while the transition is running. - Compare the "Interaction to Next Paint" (INP) score before and after this change, as discussed in INP Optimization: Architecting Non-Blocking DOM Updates.
Common Pitfalls
- Wrapping Everything: Don't wrap every
setStateinstartTransition. If you wrap something that needs to be immediate (like a checkbox toggle or a button click), the UI will feel sluggish and unresponsive. - Missing Dependencies: Since
startTransitionis a function, ensure that any state derived inside it is correctly handled. If you useuseMemofor the heavy calculation inside the transition, the state update won't actually be deferred until the calculation is done. Always perform the state-setting action inside the transition callback. - Async/Await: You cannot use
awaitinside thestartTransitioncallback. Transitions are for synchronous state updates. If you need to handle asynchronous data fetching, look towarduseDeferredValueor Suspense, which we will cover in the next few lessons.
Recap
useTransition is the cornerstone of keeping your React application responsive during heavy data operations. By distinguishing between urgent user interactions and non-urgent data processing, you create a fluid experience that feels significantly faster to the end user. Remember: only defer updates that are visually heavy or computationally expensive.
Up next: We will explore how to synchronize deferred UI states using useDeferredValue.
Work with me

Headless WordPress + Next.js Frontend Development
Keep WordPress for content, get a lightning-fast Next.js frontend. The best of both worlds — familiar editing, modern speed.

React & Next.js Dashboard / Admin UI Development
A clean, data-rich dashboard UI in React or Next.js — charts, tables, and real-time data that your users will actually enjoy using.