Skip to main content

Form Actions and useFormStatus

React 19 extends the browser <form> model so the action prop can be a function.

From manual submit plumbing to a form Action
Manual onSubmit flow
preventDefault β†’ set submitting β†’ call async work β†’ catch β†’ clear submitting.
Function Action flow
Browser form semantics + 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>
);
}
What the form workflow combines
1Browser collects FormData
2Action runs
3Pending state is available
4Action returns result state
5UI renders outcome

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 lookup
Parent <form>
Owns the submission being tracked.
SubmitButton
Calls useFormStatus().
pending Β· data Β· method Β· action

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​

Pending state has different owners
useActionState isPending
Pending state for Actions dispatched by that Hook.
useFormStatus pending
Pending state for the nearest parent form submission.

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​

Client feedback vs server authority
Client validation
Fast feedback Β· required fields Β· formatting Β· local UX.
Server validation
Authorization Β· ownership Β· allowed values Β· business rules Β· security-sensitive constraints.

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​

Production form architecture
Feature Form
Chooses the Action Β· owns domain result state Β· renders the fields.
SubmitButton
Uses useFormStatus for submission presentation.
FieldError
Renders structured validation state accessibly.
Server mutation boundary
Re-validates authorization, ownership, data shape, and business rules.

Common mistakes​

  • Calling useFormStatus in the component that creates the form instead of a descendant.
  • Duplicating pending state that already has one clear owner.
  • Forgetting name on 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​

Which form primitive owns this concern?
Need Action result state + pending lifecycle?useActionState
Need generic descendant submit status?useFormStatus
Need every keystroke to drive rendering?Controlled input state
Field only matters at submission?Browser-owned form control may be simpler
Need authoritative validation?Server boundary

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​

Next​

Continue with Optimistic UI with useOptimistic.