Skip to the page

React 19.x: Actions, forms and Server Components · senior

Actions, form actions, useActionState and useFormStatus

An Action is an async function run inside a transition; <form action={fn}> calls it with FormData, and useActionState(reducerAction, initialState) gives you the last result, a dispatch function and isPending, replacing hand-written loading/error state.

The notes

What you must know

  • const [state, formAction, isPending] = useActionState(async (prevState, formData) => {...}, initialState) then <form action={formAction}>.
  • The action receives the previous state first; with a form, FormData is the second argument. Its return value becomes the new state.
  • Calls are queued and run one after another, each getting the previous result. If it throws, React cancels queued actions and shows the nearest error boundary; for expected errors (validation), return them in state instead of throwing.
  • Calling dispatchAction outside a transition or Action prop logs an error and isPending will not update; wrap with startTransition when not using a form/button prop.
  • useFormStatus() (from react-dom) reads { pending, data, method, action } of the parent <form> from any child, for example a reusable SubmitButton.
  • Successful form actions reset uncontrolled fields automatically; return the submitted values to re-fill them on validation errors.
  • With a Server Function as the action, the form works before JavaScript loads (progressive enhancement); permalink (third argument) handles navigation before hydration.
  • React 19.3: onReset fires when React auto-resets a form after a Server Action; the submitter is included in submit events.

The red pen

Common traps: mistake → fix

  • Mistake: "Still call e.preventDefault() and manage pending/error by hand"

    Fix: that is the pattern Actions replace.

  • Mistake: "useActionState runs actions in parallel"

    Fix: it queues them sequentially.

  • Mistake: "useFormStatus works in the same component that renders the form"

    Fix: it reads the PARENT form; use it in a child.

  • Mistake: "Actions require Next.js"

    Fix: client Actions work in any React 19 app.

Easy to hard

Questions interviewers ask, easy to hard

  1. Rewrite this "update name" form (three useStates and a try/catch) using React 19 Actions.
  2. What is the signature of the function you pass to useActionState?
  3. How does a nested submit button know the form is pending?
  4. Does the form work before JavaScript loads?
  5. What happens with rapid sequential submissions and errors?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview