A Practical Guide to React 19 Actions

How many times have you written manual isLoading or isPending state checks just to show a spinner during a form submission? React 19 completely changes this experience by introducing native Actions, turning asynchronous operations into first-class citizens.
The Async State Mess
Before React 19, handling mutations in forms required writing repetitive boilerplate code. You had to:
- Initialize a loading state hook:
const [isPending, setIsPending] = useState(false) - Set it to
truewhen submission begins:setIsPending(true) - Wrap the async fetch call in a
try/catchblock - Reset
setIsPending(false)in thefinallyblock - Manually render loading spinners on buttons and disable inputs
This manual coordination was error-prone, led to visual glitches, and increased component complexity.
Enter React 19 Actions
In React 19, if you pass an asynchronous function to a DOM element, React automatically manages the pending state, error boundaries, and optimistic updates. Any function that performs an async action is known as an Action.
React automatically tracks the execution of your async function and provides hooks to interact with its state.
The useActionState Hook
To handle form state, React 19 introduces useActionState (which was previously called useFormState in experimental builds). It takes your action function and an initial state, returning the updated state, the wrapped action function, and a boolean indicating if the action is currently executing.
import { useActionState } from 'react';
// An async server action
async function updateProfile(prevState: any, formData: FormData) {
try {
const name = formData.get("username");
await api.post("/profile/update", { name });
return { success: true, message: "Profile updated!" };
} catch (err) {
return { success: false, message: "Failed to update." };
}
}
function ProfileForm() {
const [state, formAction, isPending] = useActionState(updateProfile, null);
return (
<form action={formAction} class="space-y-4">
<input name="username" type="text" required disabled={isPending} />
<button type="submit" disabled={isPending}>
{isPending ? "Saving..." : "Update Profile"}
</button>
{state && (
<p class={state.success ? "text-green-500" : "text-red-500"}>
{state.message}
</p>
)}
</form>
);
}Accessing Pending States with useFormStatus
What if a nested submit button needs to know if the parent form is pending, but you don't want to prop-drill the isPending boolean? React 19 provides the useFormStatus hook.
This hook acts like a context reader, automatically reading the status of the nearest parent <form>:
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending, data, method, action } = useFormStatus();
return (
<button type="submit" disabled={pending} class="btn">
{pending ? "Submitting..." : "Save Changes"}
</button>
);
}[!NOTE]
useFormStatusmust be called from a component that is rendered inside a<form>. It will not read form status if called in the same component that declares the<form>.
Optimistic UI Updates
React 19 also ships with useOptimistic to make user actions feel instantaneous. It lets you display the final result of an operation before the server call actually finishes, then rolls back automatically if the action fails.
import { useOptimistic } from 'react';
function ChatList({ messages }) {
const [optimisticMessages, addOptimisticMessage] = useOptimistic(
messages,
(state, newMessage: string) => [...state, { text: newMessage, sending: true }]
);
async function formAction(formData: FormData) {
const text = formData.get("message") as string;
addOptimisticMessage(text);
await sendMessageToDatabase(text); // Async action
}
return (
<div>
{optimisticMessages.map((m, i) => (
<p key={i} class={m.sending ? "opacity-50" : ""}>{m.text}</p>
))}
<form action={formAction}>
<input name="message" type="text" />
<button type="submit">Send</button>
</form>
</div>
);
}Practical Takeaways
When applying React 19 Actions in your codebase:
- Use
actiondirectly on<form>elements instead of registeringonSubmithandlers. - Adopt
useActionStateto encapsulate status management, return messages, and input states. - Rely on
useFormStatusinside child components to dynamically style buttons and loaders. - Pair mutations with
useOptimisticfor high-frequency actions like liking posts or sending chats.
Conclusion
React 19 Actions remove loading boilerplate, streamline state updates, and make application experiences feel responsive. By native tracking of async flows, React lets you write simple, declarative code that handles edge cases automatically.
- Automated loaders: Say goodbye to manual
isPendinghooks. - Context-aware controls: Leverage
useFormStatusfor clean child component integrations. - Optimistic performance: Use
useOptimisticto hide server latency.
Ready to try React 19 Actions? Convert your next form submission to use useActionState and see how much boilerplate you can delete!