React 19 Actions Replaced My Form Boilerplate
Pending flags, error state, optimistic rows, and a reset after submit. I used to write all of it by hand for every form. React 19 turned most of it into three hooks and a function passed to the form.
Every form I built before last month had the same skeleton. A useState for the pending flag, another for the error, an onSubmit that called preventDefault, a try/catch/finally, and a manual reset when it worked. Multiply that by every dashboard with ten forms and it's a lot of code that says nothing about the feature.
React 19 shipped stable in December. The headline feature is Actions, and after a few weeks of moving forms over, most of that skeleton is gone.
What an Action is
An Action is just an async function you hand to React, usually through a form's action prop. React runs it in a transition, tracks whether it's pending, and resets uncontrolled form fields when it finishes.
The before and after, for a simple "add note" form:
function AddNote() {
const [pending, setPending] = useState(false);
const [error, setError] = useState<string | null>(null);
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setPending(true);
setError(null);
try {
await saveNote(new FormData(e.currentTarget));
e.currentTarget.reset();
} catch (err) {
setError("Could not save the note.");
} finally {
setPending(false);
}
}
return <form onSubmit={onSubmit}>{/* fields, button, error */}</form>;
}function AddNote() {
const [error, submit, pending] = useActionState(async (_prev: string | null, data: FormData) => {
const ok = await saveNote(data);
return ok ? null : "Could not save the note.";
}, null);
return <form action={submit}>{/* fields, button, error */}</form>;
}Same behavior. The state machine I kept rewriting is now React's job.
The three hooks I actually use
| Hook | What it replaces |
|---|---|
useActionState | The pending flag, the error state, and the try/catch |
useFormStatus | Prop drilling pending into a submit button |
useOptimistic | Hand-written "show it now, roll back if it fails" code |
useFormStatus is the small one I like most. A submit button can read the status of the form it sits in, so a shared <SubmitButton> disables itself without anyone passing it a prop:
function SubmitButton({ children }: { children: React.ReactNode }) {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? "Saving…" : children}
</button>
);
}useOptimistic is the one that changed how lists feel. Add a row, show it immediately in a faded state, and React swaps it for the real one when the action finishes, or drops it if the action throws.
What didn't change
- Validation still belongs on the server. Actions make the client code shorter. They don't make client checks trustworthy.
- Controlled inputs still work. Field reset only applies to uncontrolled inputs, so a form that mirrors every keystroke into state still needs its own reset.
- Complex forms still want a form library. Multi-step wizards with field-level rules are still easier with one. The win is that simple forms no longer need it.
Why it matters
The forms in an admin panel are rarely interesting. They're the part of the codebase that grows fastest and gets read least. Deleting the boilerplate from them means the code that's left is the part that's actually about the feature: what gets saved, and what the user sees when it doesn't.
Keep reading
All posts2025
3 min
React Compiler 1.0 and the useMemo I Got to Delete
The compiler memoizes for you at build time. What to remove, what to keep, and the rule it quietly enforces.
reactfrontend3 min
Server State Is Not App State
What changed once I stopped putting API data in a global store and let TanStack Query own it. Keys, invalidation, and the two settings that matter most.
reactfrontend