Building Disabled Submit Buttons
You'll learn how to create submit buttons that automatically disable themselves during form submission to prevent accidental double-clicks.
The Problem: Double Submission
Users often click submit buttons multiple times, either impatiently or accidentally. Without protection, this triggers duplicate API calls, creating multiple orders, posts, or payments. The traditional solution requires manually tracking loading state and passing props down to buttons—messy and error-prone.
The useFormStatus Solution
With useFormStatus, submit buttons can read the parent form's pending state directly—no prop drilling required:
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Submitting...' : 'Submit'}
</button>
);
}
function MyForm({ onSubmit }) {
return (
<form action={onSubmit}>
<input name="email" type="email" />
<SubmitButton />
</form>
);
}
How It Works
When the form action starts executing, pending becomes true. Your button component re-renders, disabling itself and updating the label. Once the action completes (success or error), pending returns to false.
Think of it like a motion-sensor door: the button "senses" its parent form's state without needing explicit wiring. It just works by being inside the <form>.
Why This Pattern Matters
- No manual state management in the parent component
- Self-contained button logic—drop it into any form
- Built-in accessibility—
disabledattribute prevents keyboard submission too - Works with progressive enhancement—even without JavaScript, forms still submit once
Key Takeaway: Use useFormStatus inside submit button components to create self-disabling buttons that prevent double-submission by reading the form's pending state directly.