Next.jsMedium

What is useFormState and useFormStatus?

useFormState was the React DOM hook for reading the result of a form action. In React 19 it was renamed to useActionState, moved to the react package, and gained an isPending value. useFormStatus (from react-dom) gives a component the pending status of the <form> it is rendered inside.

useActionState (formerly useFormState)

  • const [state, formAction, isPending] = useActionState(action, initialState, permalink?).
  • action(prevState, formData) returns the next state, such as validation errors or a success message.
  • Pass formAction to <form action> or <button formAction>.
  • isPending is true while the action runs.
  • Import from react. useFormState from react-dom is deprecated and logs a warning.

useFormStatus

  • const { pending, data, method, action } = useFormStatus() from react-dom.
  • Must be called in a component inside the <form>, not in the component that renders the form.
  • Ideal for reusable submit buttons and inline spinners.

Choosing between them

  • Need the action's result: useActionState.
  • Need only "is this form submitting" deep in the tree: useFormStatus.
  • They are often combined: useActionState in the form component, useFormStatus in the submit button.

Related

useOptimistic for showing the expected result before the server responds, and useTransition for non-form actions.

Interview tip

Mention the rename: answering with useFormState only signals an outdated knowledge base.

Code example

tsx
1// app/feedback/form.tsx
2"use client";
3
4import { useActionState } from "react"; // was: useFormState from "react-dom"
5import { useFormStatus } from "react-dom";
6import { sendFeedback } from "./actions"; // (prev, formData) => { message: string }
7
8function SubmitButton() {
9 const { pending } = useFormStatus(); // reads the parent <form>'s status
10 return <button disabled={pending}>{pending ? "Sending…" : "Send"}</button>;
11}
12
13export function FeedbackForm() {
14 const [state, formAction, isPending] = useActionState(sendFeedback, { message: "" });
15
16 return (
17 <form action={formAction} aria-busy={isPending}>
18 <textarea name="text" required />
19 <SubmitButton />
20 {state.message && <p role="status">{state.message}</p>}
21 </form>
22 );
23}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app