Form Actions and useFormStatus
React 19 extends the browser <form> model so the action prop can be a function.
preventDefault β set submitting β call async work β catch β clear submitting.FormData + React Action lifecycle + local pending state.The browser form remains important. React adds coordination around it rather than replacing it.
Function-valued actionβ
async function saveProfile(formData) {
const name = formData.get('name');
await updateProfile({name});
}
function ProfileForm() {
return (
<form action={saveProfile}>
<input name="name" />
<button type="submit">Save</button>
</form>
);
}
When the form submits, React calls the function with FormData.
This differs from a traditional URL action:
<form action="/checkout" method="post">
Both are valid browser/React models, but they mean different things.
Keep native form semanticsβ
A function Action is not a reason to abandon semantic HTML. Keep labels, name attributes, appropriate input types, submit buttons, browser validation where useful, and server validation for trust boundaries.
<form action={signupAction}>
<label htmlFor="email">Email</label>
<input id="email" name="email" type="email" required />
<button>Sign up</button>
</form>
Why name mattersβ
FormData is created from successful form controls identified by name:
<input name="email" />
async function signupAction(formData) {
const email = formData.get('email');
}
An input can be visible while still being absent from FormData if it is not represented as a successful named form control.
Form Actions + useActionStateβ
The Action returned by useActionState can be passed directly to a form:
const initialState = {message: null, error: null};
async function submit(previousState, formData) {
const email = formData.get('email');
if (!email) {
return {message: null, error: 'Email is required'};
}
await saveEmail(email);
return {message: 'Saved', error: null};
}
function NewsletterForm() {
const [state, formAction, isPending] = useActionState(
submit,
initialState,
);
return (
<form action={formAction}>
<input name="email" type="email" />
<button disabled={isPending}>Subscribe</button>
{state.error && <p role="alert">{state.error}</p>}
{state.message && <p>{state.message}</p>}
</form>
);
}
useFormStatusβ
useFormStatus comes from react-dom:
import {useFormStatus} from 'react-dom';
It returns status information for the latest submission of the nearest parent form:
const {
pending,
data,
method,
action,
} = useFormStatus();
Pending submit buttonβ
function SubmitButton() {
const {pending} = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Submittingβ¦' : 'Submit'}
</button>
);
}
function ContactForm({action}) {
return (
<form action={action}>
<input name="message" />
<SubmitButton />
</form>
);
}
Critical placement ruleβ
useFormStatus tracks a parent form, not a form returned by the same component.
useFormStatus().This will not track the form rendered by the same component:
function Form() {
const {pending} = useFormStatus(); // π© no parent form
return (
<form action={save}>
<button disabled={pending}>Save</button>
</form>
);
}
Extract a descendant component instead.
Submitted dataβ
data exposes the FormData currently being submitted:
function StatusMessage() {
const {pending, data} = useFormStatus();
if (!pending || !data) return null;
return <p>Saving {data.get('displayName')}β¦</p>;
}
This often produces better feedback than a generic spinner.
method and actionβ
The status object also includes form submission metadata:
const status = useFormStatus();
status.method;
status.action;
For function Actions, status.action can reference the function used by the parent form.
useActionState pending vs useFormStatus pendingβ
Use the abstraction that owns the UI concern. A design-system submit button often fits useFormStatus because it does not need to know which Action Hook produced the form Action.
Multiple intents with formActionβ
A button can override a form's Action:
<form action={saveAction}>
<button>Save</button>
<button formAction={deleteAction}>Delete</button>
</form>
This can represent distinct user intents over the same fields. Keep authorization, validation, confirmation, and recovery requirements specific to each operation.
Validation and trust boundariesβ
Browser/client validation improves UX; it is not a security boundary.
Expected validation errors can be returned as structured useActionState state and rendered near the relevant field.
Controlled vs browser-owned fieldsβ
React Actions do not make controlled inputs obsolete.
<input name="email" defaultValue={initialEmail} />
A browser-owned field can remain simple until submission.
const [email, setEmail] = useState(initialEmail);
<input
name="email"
value={email}
onChange={event => setEmail(event.target.value)}
/>
Use controlled state when rendering must react to every edit.
Reset behaviourβ
Successful function-Action form flows can reset uncontrolled browser-owned controls. Controlled values remain driven by React state and must be updated by their owner.
That difference is another reason to make ownership explicit.
Progressive enhancementβ
With React Server Components, Server Functions, and framework support, form Actions can participate in progressive enhancement so a form can submit before hydration completes.
A client-only Vite application should not pretend it has Server Function semantics merely because it uses <form action={fn}>.
Production responsibility mapβ
useFormStatus for submission presentation.Common mistakesβ
- Calling
useFormStatusin the component that creates the form instead of a descendant. - Duplicating pending state that already has one clear owner.
- Forgetting
nameon submitted fields. - Assuming every function Action is a Server Function.
- Relying only on client/browser validation.
- Treating controlled and browser-owned reset behaviour as the same thing.
Decision guideβ
Interview questionsβ
Junior: What argument does a function-valued form Action receive?
Mid-level: Why does useFormStatus need to be called from a descendant of the form rather than the component that returns the form?
Senior: How would you divide responsibility between useActionState, useFormStatus, browser-owned form fields, controlled fields, and server validation?
Referencesβ
- https://react.dev/reference/react-dom/components/form
- https://react.dev/reference/react-dom/hooks/useFormStatus
- https://react.dev/reference/react/useActionState
Nextβ
Continue with Optimistic UI with useOptimistic.