Sub topic 10
Common pitfalls: why pending stays false
This chapter assumes you can write React function components, know the basics of FormData, and have already built a SubmitButton with useFormStatus in the earlier chapters. Here you will learn the mistakes that leave pending stuck at false, and how to find which one you have made.
How the hook finds its form
useFormStatus does not take a form as an argument. React reads the status from the nearest parent <form> in the component tree, much like context. So pending is true only when both of these hold:
- The component calling the hook is rendered inside a
<form>. - That form is being submitted through a function passed to its
actionprop.
Nearly every "pending is always false" bug breaks one of these two conditions.
Pitfall 1: calling the hook in the form's own component
This is the most common mistake. The hook runs in the component that renders the <form>, so there is no parent form to read.
import { useFormStatus } from 'react-dom';
// Incorrect: this component renders the form, it is not inside it.
function BrokenForm({ action }) {
const { pending } = useFormStatus();
return (
<form action={action}>
<input name="name" />
<button type="submit" disabled={pending}>Save</button>
</form>
);
}The fix is to move the hook into a child component and render that child inside the form.
'use client';
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving...' : 'Save'}
</button>
);
}
export default function FixedForm() {
async function save(formData) {
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log('Saved', formData.get('name'));
}
return (
<form action={save}>
<input name="name" />
<SubmitButton />
</form>
);
}SubmitButton is rendered inside the <form>, so its hook call finds a parent form.
Pitfall 2: the form does not use a function action
The hook tracks submissions started through the action prop. A form that uses onSubmit with event.preventDefault() and its own fetch call never goes through that path, so React has nothing to report.
// pending stays false: the submission is handled by onSubmit, not action.
<form onSubmit={async (event) => {
event.preventDefault();
await saveToServer(new FormData(event.currentTarget));
}}>
<SubmitButton />
</form>Pass the function to action instead. React then passes the FormData to your function and tracks the submission for you. If you still need onSubmit for other reasons, keep your own useState flag for that form. useFormStatus will not help there.
Pitfall 3: the button is not a descendant of the form
Position in the component tree is what counts, not position on the page. A SubmitButton that is rendered outside the <form> element but linked to it with the HTML form="id" attribute still has no parent form in React's tree. Likewise, a portal-based component that you place beside the form instead of inside it does not see the form's status. Render the component as a descendant of the form element.
Pitfall 4: the action finishes too fast to see
Sometimes the hook works and you cannot see it. If the action returns immediately, pending becomes true and goes back to false within a frame, and the UI never visibly changes.
To test your pending UI, add a delay to the action while you develop:
await new Promise((resolve) => setTimeout(resolve, 1000));Remove the delay afterwards. In a real app, a slow network or server will produce the delay for you. You can also throttle the network in your browser's developer tools.
Pitfall 5: wrong import or missing client boundary
useFormStatus is exported from react-dom, not from react. Importing it from react gives you undefined, and calling it throws a TypeError.
// Incorrect
import { useFormStatus } from 'react';
// Correct
import { useFormStatus } from 'react-dom';In a framework with Server Components, such as Next.js, a hook cannot run in a Server Component. Put 'use client'; at the top of the file that calls useFormStatus. The form itself can stay in a Server Component, as shown in the Server Actions chapter.
A debugging checklist
When pending stays false, check these in order.
The last branch covers nested or duplicated forms. HTML does not allow a <form> inside another <form>. If you have two sibling forms, each button reads the status of its own parent only, so make sure the button sits in the form you are actually submitting.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| `pending` always `false`, no errors | Hook called in the component that renders the form | Move it to a child component |
| `pending` always `false`, form uses `onSubmit` | Submission does not use the `action` prop | Pass a function to `action` |
| `pending` flashes too briefly | Action resolves almost instantly | Add a temporary delay when testing |
| `TypeError` when calling the hook | Imported from `react` | Import from `react-dom` |
| Error about hooks in a Server Component | Missing client boundary | Add `'use client';` to the file |
Exercise
A teammate's component renders <form action={save}>, calls const { pending } = useFormStatus(); at the top of the same component, and passes pending to the submit button's disabled prop. The save action takes two seconds, but the button never disables. What is wrong, and how do you fix it?
Show answer
The hook is called in the same component that renders the form, so there is no parent form for it to read, and pending stays false. Create a separate SubmitButton component that calls useFormStatus and renders the <button>, then render <SubmitButton /> inside the <form>. The action prop on the form can stay as it is.
Exercise
A form uses onSubmit={handleSubmit} where handleSubmit calls event.preventDefault() and then await fetch(...). A child SubmitButton uses useFormStatus, and pending never becomes true. Why, and what change makes the hook work?
Show answer
The submission does not go through the form's action prop, so React does not track it as a form action. Move the logic into an async function that receives FormData, pass it as <form action={handleAction}>, and remove the preventDefault handling. The child SubmitButton will then see pending as true while the function runs.