Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Choose Between React’s useActionState and useFormStatus

Use useActionState to store and render an action’s result; use useFormStatus inside a form to show its submission status and details.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use useActionState when you need to keep and display the value returned by a form action. Use useFormStatus when a component inside a form needs to know whether that form is submitting or inspect its current submission. They can work together, but they answer different questions.

What each hook does

Hook Use it when Where to call it What it provides
useActionState The action’s return value should become component state, such as a validation result or confirmation. At the top level of the component or custom hook that owns the action. Current action state, a dispatcher, and an isPending flag.
useFormStatus A child control or status indicator needs information about its parent form’s submission. In a component rendered inside the form being observed. pending, submitted data, the form method, and the form action reference.

The hooks are complementary: one exposes the action’s result as state; the other exposes the parent form’s submission status and details. See the official useActionState reference and useFormStatus reference.

As an Amazon Associate I earn from qualifying purchases.

Use useActionState to render an action result

The current reference signature is useActionState(action, initialState, permalink?). It returns three values: the current state, a dispatcher to pass to the form, and isPending. The initial state is used before the action has returned a value; each returned value becomes the next state.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { useActionState } from 'react';

async function saveName(previousState, formData) {
  const name = formData.get('name');

  if (!name) {
    return { error: 'Enter a name.' };
  }

  return { message: `Saved ${name}.` };
}

function NameForm() {
  const [state, formAction, isPending] = useActionState(
    saveName,
    { message: '', error: '' }
  );

  return (
    <form action={formAction}>
      <label>
        Name
        <input name="name" />
      </label>
      <button disabled={isPending}>
        {isPending ? 'Saving…' : 'Save'}
      </button>
      {state.error && <p role="alert">{state.error}</p>}
      {state.message && <p>{state.message}</p>}
    </form>
  );
}

Wrapping an action with useActionState changes its arguments: the previous state is first, and the action’s usual payload follows it. For a form action, that payload is the submitted FormData. If a function previously expected formData as its first argument, update its signature or it will read the wrong value.

Return known failures; throw unexpected ones

For expected outcomes such as missing or invalid fields, return structured error information and render it from state. The React reference describes throwing for unexpected failures so the nearest Error Boundary can handle them. See React’s error-handling guidance for useActionState.

Use useFormStatus for a child component’s submission feedback

Import useFormStatus from react-dom. It takes no arguments and returns an object. A nested button can use pending to disable itself or change its label while its parent form is being submitted.

import { useFormStatus } from 'react-dom';

function SubmitButton() {
  const { pending } = useFormStatus();

  return (
    <button type="submit" disabled={pending}>
      {pending ? 'Submitting…' : 'Submit'}
    </button>
  );
}

function ContactForm({ action }) {
  return (
    <form action={action}>
      <input name="email" type="email" />
      <SubmitButton />
    </form>
  );
}

The component calling the hook must be rendered inside the form it observes. Calling useFormStatus in ContactForm, the same component that creates the <form>, does not track that form. Move the hook into a descendant such as SubmitButton. The React reference also documents data as submitted FormData or null, method as get or post, and action as the parent form’s function action reference or null in the documented cases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can a form use both hooks?

Yes. Use useActionState in the component that needs the returned result, and put a separate useFormStatus consumer inside the form if a nested control needs submission details. For example, the form owner can render a validation message from action state while a nested submit button disables itself during submission. If pending feedback is the only requirement, useFormStatus alone may be sufficient.

Server Functions, hydration, and permalink

In a framework scenario that supports React Server Components and Server Functions, React documents that a Server Function’s response can be shown before the page is hydrated. This is not a blanket guarantee for every client-only form.

The optional permalink argument to useActionState supports progressive enhancement on dynamic pages using a Server Function. If the form is submitted before JavaScript loads, the browser can navigate to that URL. The destination must render the same form component with the same action and permalink for React to pass the state through. After hydration, the permalink has no effect. Consult the useActionState reference for the documented conditions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand queued actions and cancellation

useActionState queues calls so each action receives the state returned by the previous call. That ordering is useful when later submissions depend on earlier results, but sequential asynchronous work can take longer if many calls are queued. React suggests considering useOptimistic or, for more complex cases, cancelling queued actions or not using useActionState.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cancellation is not a rollback: stopping client-side work does not undo a server-side mutation that has already happened. Cancel only when the side effect can safely be ignored or retried. See React’s guidance on queued actions.

Which hook should you start with?

  • Choose useActionState if you need to display or otherwise use the value an action returns.
  • Choose useFormStatus if a descendant control or indicator needs submission status or details from its parent form.
  • Use both when the UI needs both an action result and separate feedback inside the form.

The current references describe these APIs without stating a minimum React version or a full framework compatibility matrix. Check the documentation for the React and framework setup you use rather than inferring a version requirement from the hook names.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.