Actions and async Transitions
React 19 gives a first-class name and set of patterns to a workflow that modern applications perform constantly.
React calls functions executed inside a Transition Actions.
An Action is not a replacement for event handlers, Effects, or API functions. It coordinates updates that may include asynchronous work while React treats the resulting UI update as non-urgent.
Start with the problemβ
Imagine changing the quantity of an item:
async function updateQuantity(nextQuantity) {
const response = await fetch('/api/cart', {
method: 'POST',
body: JSON.stringify({quantity: nextQuantity}),
});
return response.json();
}
The network request is ordinary JavaScript. The React question is how the UI should behave while it is happening and when its result updates rendered state.
useTransitionβ
import {useState, useTransition} from 'react';
function QuantityEditor() {
const [quantity, setQuantity] = useState(1);
const [isPending, startTransition] = useTransition();
function saveQuantity(nextQuantity) {
startTransition(async () => {
const saved = await updateQuantity(nextQuantity);
startTransition(() => {
setQuantity(saved.quantity);
});
});
}
return (
<button disabled={isPending} onClick={() => saveQuantity(quantity + 1)}>
{isPending ? 'Savingβ¦' : `Quantity: ${quantity}`}
</button>
);
}
setTimeout.startTransition changes update priority; it does not postpone the callback.
Action naming is a conventionβ
A callback intended to run as Transition work can use an Action suffix:
function SubmitButton({submitAction}) {
const [isPending, startTransition] = useTransition();
return (
<button
disabled={isPending}
onClick={() => {
startTransition(async () => {
await submitAction();
});
}}
>
Submit
</button>
);
}
The name is a convention, not special JavaScript syntax.
Actions can contain side effectsβ
A reducer passed to useReducer must remain pure. An Action may perform side effects:
startTransition(async () => {
const result = await saveProfile(formValues);
// state update follows
});
That difference matters when comparing useReducer with useActionState.
Actions are not Effectsβ
Do not move user-triggered work into an Effect merely because it is asynchronous.
Bad:
useEffect(() => {
if (shouldSave) {
saveProfile();
}
}, [shouldSave]);
Better:
function handleSave() {
startTransition(async () => {
await saveProfile();
});
}
Pending stateβ
useTransition returns:
const [isPending, startTransition] = useTransition();
Use isPending for local feedback:
<button disabled={isPending}>
{isPending ? 'Updatingβ¦' : 'Update'}
</button>
Pending UI should usually preserve context instead of replacing the whole screen with a global spinner.
State updates after awaitβ
A current React limitation matters when an Action awaits asynchronous work.
startTransition(async () => {
const result = await saveSomething();
setValue(result); // not automatically Transition work today
});
Wrap state updates after the await in another startTransition:
startTransition(async () => {
const result = await saveSomething();
startTransition(() => {
setValue(result);
});
});
Treat this as a current implementation limitation, not a timeless conceptual rule.
Urgent vs non-urgent updatesβ
Do not put controlled input state itself in a Transition:
function SearchBox() {
const [query, setQuery] = useState('');
function handleChange(event) {
setQuery(event.target.value); // immediate
}
return <input value={query} onChange={handleChange} />;
}
Use synchronous state for the input. useDeferredValue or a separate Transition-backed result can lag behind without making typing lag.
Action propsβ
Reusable components can own pending presentation while callers provide domain behavior:
function SaveButton({action}) {
const [isPending, startTransition] = useTransition();
return (
<button
disabled={isPending}
onClick={() => {
startTransition(async () => {
await action();
});
}}
>
{isPending ? 'Savingβ¦' : 'Save'}
</button>
);
}
<SaveButton action={() => saveProfile(profile)} />
Request ordering still mattersβ
Raw async Transitions do not automatically solve race conditions.
useActionState and form Actions help with common ordered mutation flows. Custom async Transition code may still need explicit request-ordering logic.
Common mistakesβ
- Using Actions for every async function. A normal async event handler is still valid.
- Treating Transition work as delayed work. The callback runs immediately.
- Ignoring failures. Expected validation/domain errors need a user-facing state model; unexpected failures need an error strategy.
- Showing pending UI too broadly. Keep feedback close to the operation.
- Using Transition state to control text inputs.
Production decision guideβ
Interview questionsβ
Junior: What does startTransition change about a state update?
Mid-level: Why should controlled input state usually not be updated inside a Transition?
Senior: What race conditions can remain when building custom async Actions, and when would useActionState be a better abstraction?
Referencesβ
- https://react.dev/reference/react/useTransition
- https://react.dev/reference/react/startTransition
- https://react.dev/blog/2024/12/05/react-19
Nextβ
Continue with useActionState to manage Action result state, pending state, and ordered updates.