Disable a submit button with useFormStatus
Read a React 19 form's pending state from a child component to disable its submit button during the action.
You pass an async function to <form action>, the save takes a second, and the user clicks Save again before it finishes. You want the button disabled while the form submits.
React 19 added useFormStatus to react-dom for this. A child component can read the enclosing <form>'s submission status and use it to disable the button.
Read pending in a child component
import { useFormStatus } from 'react-dom'
async function saveProfile(formData) {
const response = await fetch('/api/profile', { method: 'POST', body: formData })
if (!response.ok) throw new Error('Could not save profile')
}
function SubmitButton() {
const { pending } = useFormStatus()
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving…' : 'Save'}
</button>
)
}
export function ProfileForm() {
return (
<form action={saveProfile}>
<label>
Name
<input name="name" />
</label>
<SubmitButton />
</form>
)
}With a working /api/profile endpoint, click Save. The button reads "Saving…" with disabled set until saveProfile resolves, then it reads "Save" again. A second click during the save does nothing, because a disabled button does not submit.
The hook returns four fields. pending is the one you want here.
data is the FormData being submitted, method is 'get' or 'post', and action is the function you passed to the form. data is null while the form is idle. action can be null, for example when the form uses a URL action.
Why pending stays false
The first thing to check is whether the hook is called in the component that renders the form.
function ProfileForm() {
const { pending } = useFormStatus() // never true
return (
<form action={saveProfile}>
<button type="submit" disabled={pending}>Save</button>
</form>
)
}pending stays false here for every click. The hook only reports on a <form> above the component that calls it, never on a form that component renders. Move the button into its own component, as in the first example, and the hook finds the form.
Check how the form submits. An onSubmit handler that calls preventDefault() and starts a plain fetch leaves the button enabled. To track that handler, start a Transition in the same submit event and run the async save inside it.
Where I put it
I keep one SubmitButton next to the other form controls and drop it into each form. It takes a label and a pending label as props, and the forms that use it hold no submitting state at all.