Skip to content
Tutorials Center
My learning

Topics

React Reference ยท react-dom Resource and Form APIs

The <form action> prop in React

Reference for the React form action prop: pass a function to receive FormData, what resets afterwards, formAction on buttons, errors, and what onSubmit changes.

In plain HTML the action attribute of a <form> is a URL, and submitting the form navigates to it. React 19 lets you pass a function instead. When the user submits, React prevents the page navigation, builds a FormData object from the form's fields, and calls your function with it. The call runs inside a transition, so your page stays responsive and tools such as useFormStatus can see that the form is pending.

The same prop name works on a <button>, <input type="submit"> and <input type="image"> as formAction, so one form can have several submit actions.

JSX
function saveName(formData) {
  console.log(formData.get('name'));
}

<form action={saveName}>
  <input name="name" />
  <button>Save</button>
</form>

Try it

A function as the form action

Change the name and press Greet. The greeting appears, and the name box jumps back to Ada: React resets uncontrolled fields to their defaults once the action finishes.

One form, two actions

The button's formAction replaces the form's action for that submission only. Both functions get the same kind of FormData.

Syntax

JSX
<form action={fn}>...</form>
<button formAction={fn}>...</button>
TypeScript
type FormAction = (formData: FormData) => void | Promise<void>;

interface FormProps {
  action?: string | FormAction;
}
Name Description
action (form) A function called with the FormData on submit, or a string URL (normal browser submission).
formAction (button, input) Same type; overrides the form's action when that button submits.
formData Argument of your function. Contains the named, enabled fields, plus the submitter button's name/value if it has them. See FormData in actions.

Returns: the return value of the function is ignored by the form itself. Use useActionState when you want the result back.

Errors / edge cases: an error thrown by the action (or a rejected promise) is rethrown during render and goes to the nearest error boundary.

Usage notes

  • Automatic reset. After the action completes, React resets the form's uncontrolled fields to their defaults. Controlled inputs keep the value from your state. See requestFormReset for manual use.
  • Async is fine. Return a promise and the form stays "pending" until it settles; read that with useFormStatus.
  • onSubmit still runs first. If your onSubmit handler calls event.preventDefault(), the function action is not called. Choose one style per form.
  • Buttons with function formAction ignore name. React needs the attribute to route the click, so a development warning says the name is overridden and that button's name/value are not in FormData. Use separate functions (as above) instead of name="intent" on those buttons.
  • A string action works like HTML: the browser submits to that URL, no JavaScript involved. For a function, React puts a placeholder javascript: URL in the real action attribute that throws if the browser ever submits the form without React (for example after form.submit()); use form.requestSubmit() in your own code.
  • Progressive enhancement. With a server function (frameworks such as Next.js), the form works before JavaScript loads. That variant needs a server; here it is read-only.
  • Fields must have name. Unnamed inputs, disabled inputs and unchecked checkboxes are not in FormData.
  • Nested forms are invalid HTML. Put buttons with formAction inside the one form instead.
  • Typing note: in TypeScript the parameter type is FormData; values from get() are FormDataEntryValue | null.