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.
function saveName(formData) { console.log(formData.get('name')); } <form action={saveName}> <input name="name" /> <button>Save</button> </form>
Try it
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.
The button's formAction replaces the form's action for that submission only. Both functions get the same kind of FormData.
Syntax
<form action={fn}>...</form> <button formAction={fn}>...</button>
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
requestFormResetfor manual use. - Async is fine. Return a promise and the form stays "pending" until it settles; read that with
useFormStatus. onSubmitstill runs first. If youronSubmithandler callsevent.preventDefault(), the function action is not called. Choose one style per form.- Buttons with function
formActionignorename. React needs the attribute to route the click, so a development warning says thenameis overridden and that button's name/value are not inFormData. Use separate functions (as above) instead ofname="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 realactionattribute that throws if the browser ever submits the form without React (for example afterform.submit()); useform.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,disabledinputs and unchecked checkboxes are not inFormData. - Nested forms are invalid HTML. Put buttons with
formActioninside the one form instead. - Typing note: in TypeScript the parameter type is
FormData; values fromget()areFormDataEntryValue | null.