useTransition is a React Hook that lets you update the state without blocking the UI.
Parameters
useTransition does not take any parameters.
Returns
useTransition returns an array with exactly two values:
boolean
The
isPending flag that tells you whether there is a pending transition.(callback: () => void, options?: StartTransitionOptions) => void
The
startTransition function that lets you mark a state update as a transition.callback: A function that updates state. React will immediately call this function, marking all state updates scheduled synchronously during this function call as transitions.options: Optional object with anameproperty (string) for debugging in React DevTools.
Usage
Marking a state update as a non-blocking transition
CalluseTransition at the top level of your component to mark state updates as transitions:
Updating the parent component in a transition
You can callstartTransition from a child component to update parent state:
Displaying a pending visual state during the transition
Show loading indicators while the transition is pending:Preventing unwanted loading indicators
In this example, thePostsTab component fetches data using Suspense. When you click the “Posts” tab, it immediately shows a pending state:
Common Patterns
Search with transitions
- Basic
- With Debounce
Navigation with transitions
Form submission with transitions
Filtering with transitions
TypeScript
Troubleshooting
Updating an input in a transition doesn’t work
You can’t use transitions for state that controls an input:React doesn’t treat my state update as a transition
Make sure the state update is inside thestartTransition callback: