Course contentsShow
← React
Lesson 1615 of 2,39639. Server Components in PracticeFree lesson

useFormStatus for Pending States

Reading form submission status to show loading indicators and disable submit buttons.

useFormStatus for Pending States

What you'll learn: How to show loading indicators and disable buttons during form submission using React's useFormStatus hook.

The Problem: Forms Without Feedback

When you submit a form using a Server Action, there's a delay while the server processes it. Without feedback, users don't know if their click worked—they might click again, causing duplicate submissions.

What useFormStatus Does

useFormStatus is a Client Component hook that reads the pending state of the parent form. It tells you whether the form is currently submitting, so you can show loading spinners, disable buttons, or display "Submitting..." text.

Important: useFormStatus must be called in a component that's rendered inside the <form>. It reads the status of the nearest parent form.

Basic Usage

'use client'
import { useFormStatus } from 'react-dom'

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

Then use this button inside your form:

// In a Server Component
async function submitForm(formData) {
  'use server'
  // Process data...
}

export default function MyForm() {
  return (
    <form action={submitForm}>
      <input name="email" />
      <SubmitButton /> {/* Reads parent form status */}
    </form>
  )
}

Think of It Like a Traffic Light

useFormStatus is like a traffic light that watches the parent form. When the form starts submitting (light turns red), pending becomes true. When it finishes (light turns green), pending returns to false.

Key Takeaway: useFormStatus reads the pending state of the nearest parent <form>, enabling you to create responsive submit buttons and loading indicators that automatically react to Server Action submissions.