Course contentsShow
← React
Lesson 1493 of 2,39637. React 19 and BeyondFree lesson

The pending Flag and Form Actions

Understand how useFormStatus.pending tracks server action execution, automatically toggling during async form submissions.

The pending Flag and Form Actions

What you'll learn: How useFormStatus().pending automatically tracks server action execution during form submissions.

The Core Mechanism

When you call useFormStatus() in a component inside a <form>, it returns an object with a pending flag. This flag automatically becomes true when the form starts executing its server action, and false when it completes. You don't manage this state yourself—React handles it.

Think of pending like an automatic "processing" light on a credit card terminal: it turns on when the transaction starts, off when it finishes, without you flipping any switches.

How It Works with Form Actions

function SubmitButton() {
  const { pending } = useFormStatus();
  
  return (
    <button type="submit" disabled={pending}>
      {pending ? 'Submitting...' : 'Submit'}
    </button>
  );
}

function MyForm({ addTodo }) {
  return (
    <form action={addTodo}>
      <input name="text" />
      <SubmitButton />
    </form>
  );
}

When the form submits and addTodo (a server action) runs, pending automatically toggles to true. When addTodo completes (or errors), pending returns to false. No manual state management required.

Why This Matters

Before React 19, you'd need separate state variables and callbacks to track async form submissions. Now the form's execution state is built-in and accessible to any child component via useFormStatus(), making loading states trivial to implement.

Key Takeaway: useFormStatus().pending automatically tracks whether a parent form's action is currently executing, toggling true during async submissions without manual state management.