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.
Theory in plain words
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
No onSubmit, no preventDefault. React passes the FormData and resets the field when the action is done.
useActionState: result + pending
The function gets the previous state first and the FormData second. What it returns becomes the next state.
useFormStatus in a child button
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
<button formAction={fn}>: a second button with a different action in the same form.startTransition(async () => { ... }): run any async work as an action.- In frameworks such as Next.js, an action can be a Server Action (a function marked
"use server") that runs on the server.
Quick quiz
1. What can the action prop of a form take in React 19?
React runs the function with the form data.
2. What does useActionState return?
The state, an action to pass to the form and a pending flag.
3. Where must useFormStatus be called?
It reads the status of its parent form.
4. What arguments does the function given to useActionState receive?
Previous state first, then the form data.
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.