React Best Practices

Chapter 5 · Practice 3 of 5

Read pending state in child components with useFormStatus

From Forms and actions in React 19

Why it matters

A reusable submit button should not need a loading prop from every form that uses it. useFormStatus from react-dom reads the status of the parent form, including pending, so the button can disable itself and change its label.

Disabling the button while pending also prevents double submits.

Example

TSX
import { useFormStatus } from 'react-dom';

function SubmitButton() {
  const { pending } = useFormStatus();
  return <button disabled={pending}>{pending ? 'Saving...' : 'Save'}</button>;
}