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

The Pending State

Using the pending boolean to show loading indicators and disable form elements during submission.

The Pending State

What you'll learn: How to use the pending boolean from useActionState to show loading indicators and disable form elements while an action is running.

The Problem with Invisible Submissions

When users submit a form, they need immediate feedback that something is happening. Without it, they might click "Submit" multiple times, wondering if their first click registered. The pending state from useActionState solves this by telling you exactly when an action is in-flight.

How pending Works

The useActionState hook returns a three-item array: [state, action, pending]. That third value is a boolean:

const [state, formAction, pending] = useActionState(submitForm, initialState);
  • pending is true from the moment the action starts until it completes
  • pending is false before submission and after the action finishes

Practical Usage Patterns

Show loading indicators:

<button type="submit">
  {pending ? "Saving..." : "Save"}
</button>

Disable form elements to prevent double-submission:

<button type="submit" disabled={pending}>
  Submit
</button>

<input type="text" disabled={pending} />

Conditional UI feedback:

{pending && <Spinner />}

Think of It Like a Traffic Light

The pending state is like a yellow traffic light on your form. When it's true (yellow), you're telling users "wait, something's happening." When it's false (green), they know they can interact freely. This prevents the "did my click work?" confusion.

Key Takeaway: The pending boolean from useActionState gives you precise, automatic tracking of when actions are running, making it trivial to create responsive, user-friendly forms with loading states and disabled controls.