Home / Learn React / Actions and Forms in React 19

Actions and Forms in React 19

React 19 lets you pass a function to a form's action. React runs it, tracks the pending state and resets the form when it succeeds. useActionState and useFormStatus make it easy.

In shortWrite <form action={fn}>. fn receives the FormData. useActionState gives you the result and a pending flag. useFormStatus tells a child button that the form is sending.

Theory in plain words

Form Action lifecycleUser submitsthe formReact makes FormDataisPending = trueYour action runs(await a request)State updatedform reset, pending false
Form Action lifecycle

What it is

An Action is a function that React runs for a form submit (or inside a transition). The form action prop can now take a function instead of a URL. useActionState(fn, initialState) wraps the function and returns [state, formAction, isPending].

Why we use it

Before, you wrote onSubmit, called preventDefault, kept loading and error in state and reset fields by hand. Actions do all that bookkeeping for you and work with Suspense and transitions.

How it works

When the form submits, React builds a FormData, calls your function inside a transition, sets isPending while it runs, stores the returned value as the new state and (for uncontrolled fields) resets the form after success.

Where it is used

  • Login, signup, contact and checkout forms
  • Add to cart and like buttons
  • Forms in frameworks where the action runs on the server (Server Actions)

A form with an action function

action={function}Try it Yourself

No onSubmit, no preventDefault. React passes the FormData and resets the field when the action is done.

useActionState: result + pending

useActionStateTry it Yourself

The function gets the previous state first and the FormData second. What it returns becomes the next state.

useFormStatus in a child button

A reusable submit buttonTry it Yourself

useFormStatus comes from react-dom, not react. It reads the status of the closest parent form, so it must be called in a child component.

Other places that take an action

Careful:If you send a form to a real server, always validate again on the server. Client checks are only for friendly messages.

Quick quiz

1. What can the action prop of a form take in React 19?

2. What does useActionState return?

3. Where must useFormStatus be called?

4. What arguments does the function given to useActionState receive?

Common questions

What can the action prop of a form take in React 19?

A function. React runs the function with the form data.

What does useActionState return?

[state, formAction, isPending]. The state, an action to pass to the form and a pending flag.

Where must useFormStatus be called?

In a component rendered inside the form. It reads the status of its parent form.