Full answer
Before React 19, a form submit needed an onSubmit handler, preventDefault, a controlled input for each field, and manual loading and error state. Actions reduce that to a function.
<form action={fn}> makes React call fn(formData) on submit. The function can be async. React runs it inside a transition, so the UI stays responsive, and it takes care of pending state. When the action finishes, React resets uncontrolled fields in the form. If you need to keep the typed value after an error, return it from the action and use it as a defaultValue.
useActionState(action, initialState) returns [state, formAction, isPending]. The action you pass receives (previousState, formData) and returns the next state, such as an error message or a success flag. Pass formAction to the form. The state updates with whatever the action returns. This is how a form shows validation errors without extra useState calls.
useFormStatus() from react-dom returns { pending, data, method, action } for the parent form. It must be called from a component rendered inside the form, not from the component that renders the form tag. That makes it ideal for a reusable submit button that disables itself while saving.
Actions are not limited to client code. With a framework that supports Server Functions, the action can be a function marked "use server", and the same form works before JavaScript loads (progressive enhancement). Because those are public endpoints, validate input and check permissions on the server.
For instant feedback, combine actions with useOptimistic. For richer control or complex fields, controlled inputs and libraries such as React Hook Form remain fine. Actions are an addition, not a replacement for every form.
import { useActionState } from 'react';
import { useFormStatus } from 'react-dom';
async function saveName(previousState, formData) {
const name = String(formData.get('name') ?? '').trim();
await new Promise((resolve) => setTimeout(resolve, 20));
if (name.length < 3) {
return { ok: false, message: 'Name needs at least 3 letters' };
}
return { ok: true, message: 'Saved ' + name };
}
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving...' : 'Save'}
</button>
);
}
export default function ProfileForm() {
const [state, formAction] = useActionState(saveName, { ok: null, message: '' });
return (
<form action={formAction}>
<input name="name" />
<SubmitButton />
<p>{state.message}</p>
</form>
);
}The action validates the name and returns a message. SubmitButton reads the pending flag from the form around it. The check submitted Al first and then Asha. In both cases React emptied the input after the action finished, so a real form returns the typed value in its state to keep it. Output of the run: after "Al": Name needs at least 3 letters | input value is "" after "Asha": Saved Asha | input value is ""
Key points
- A form accepts a function in action. React passes FormData, runs it in a transition and manages pending state.
- useActionState(action, initial) returns the state, a form action and a pending flag. The action receives the previous state first.
- useFormStatus reads the parent form's pending state and must be called from a child component.
- React resets uncontrolled fields when the action finishes, even if it returned an error.
- Server Functions use the same form API and need server-side validation.
Common mistakes
- Calling useFormStatus in the same component that renders the form element, where it always reports not pending.
- Writing the action as (formData) when it is wrapped by useActionState, which passes previousState first.
- Expecting typed values to remain after the action. Uncontrolled fields are reset.
- Treating a Server Function as private. It is reachable by anyone who can send a request.
Follow-ups
- How would you keep the user's input after a validation error?
- How does useOptimistic combine with a form action?
- What does "progressive enhancement" mean for a form that uses a Server Function?
Tips
- Show the order of arguments, previous state first. It is a common slip.
- Explain why useFormStatus must be in a child. It is a frequent follow-up.
- Be balanced: say when you would still choose a controlled form or a form library.