Sub topic 10
Common pitfalls: why pending stays false
This chapter assumes you know React function components and hooks, JSX and props, HTML forms and FormData, and async functions. It also assumes you have read the earlier chapters on form actions, the pending flag, and the child component rule. Here you will collect the ways useFormStatus can look broken, learn why each one happens, and build a short routine for finding the cause.
useFormStatus rarely fails with an error. It returns { pending: false, data: null, method: 'get', action: null }, and your button never disables. That default object is also what a correct component reads while the form is idle, so a wrong setup looks the same as a form that is not submitting. You find the cause by checking the conditions the hook depends on.
What the hook needs in order to report pending
For pending to become true, all of these must hold:
- You are on a React version that ships
useFormStatus(React 19 or later). - You import the hook from
react-dom. - The component that calls the hook is rendered as a descendant of a
<form>element. - That form's
actionprop is a function. - The function is still running, which in practice means it returns a promise that has not settled.
- The component is a Client Component that has hydrated.
Each pitfall below breaks one of these conditions.
Pitfall 1: calling the hook in the component that renders the form
This is the most common mistake. The hook reads the status of a parent form. A component cannot be its own parent, so a hook in the same component as the <form> never sees that form.
import { useFormStatus } from 'react-dom';
// Incorrect: the hook runs in the same component that renders the form.
function BrokenForm({ action }) {
const { pending } = useFormStatus();
return (
<form action={action}>
<input name="name" />
<button type="submit" disabled={pending}>Save</button>
</form>
);
}Here pending stays false because no <form> sits above BrokenForm in the tree. The <form> it renders is below it. If BrokenForm itself were inside another form, the hook would report that outer form's status, which is a different and confusing bug.
The fix is to move the hook into a child component:
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving...' : 'Save'}
</button>
);
}
export default function FixedForm({ action }) {
return (
<form action={action}>
<input name="name" />
<SubmitButton />
</form>
);
}The child does not have to be a direct child. Any depth of nesting works, as long as the component is rendered somewhere inside the <form> element. A wrapper <div>, a fieldset component, or a layout component in between is fine.
Two related cases are easy to miss:
- A button outside the form. A button that is placed outside the
<form>in the tree, even if it uses theform="form-id"HTML attribute to submit it, is not a descendant. The hook finds the form through the component tree, not through HTML attributes. Keep the status-reading component inside the form element. - Several forms on one page. Each
useFormStatuscall reads its nearest parent form. Two forms each get their own status, so one form's submission does not disable the other's button. If you want one form to block another, you need shared state, not this hook.
Pitfall 2: handling the submission with onSubmit instead of an action function
useFormStatus tracks form actions. A form action is a function passed to the form's action prop, and React runs it as a transition. A handler on onSubmit is an ordinary event handler. React does not track it, even if it is async and takes seconds.
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving...' : 'Save'}
</button>
);
}
// Incorrect: onSubmit is not a form action, so pending never turns true.
export default function OnSubmitForm() {
async function handleSubmit(event) {
event.preventDefault();
await fetch('/api/save', {
method: 'POST',
body: new FormData(event.currentTarget),
});
}
return (
<form onSubmit={handleSubmit}>
<input name="name" />
<SubmitButton />
</form>
);
}The component structure is correct, the request is slow, and the button still never disables. Switch to the action prop. React passes the form's data to your function as a FormData argument, so you no longer need event.preventDefault() or event.currentTarget:
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Saving...' : 'Save'}
</button>
);
}
export default function ActionForm() {
async function save(formData) {
await fetch('/api/save', { method: 'POST', body: formData });
}
return (
<form action={save}>
<input name="name" />
<SubmitButton />
</form>
);
}If you must keep onSubmit for another reason, such as custom validation before submitting, you can run that validation in the action function itself or keep your own useState flag for the pending state. Do not expect useFormStatus to see it.
A string action does not count either
If action is a URL string, or you leave it off, the browser submits the form natively and the page navigates. React is not running a function, so pending stays false and the hook's action field is null. Only a function passed to action is tracked.
Pitfall 3: the action finishes too quickly to see
pending is true only while the action's promise is unsettled. If your action is synchronous, or it awaits nothing slow, the pending window lasts a few milliseconds and may never paint.
// Pending lasts almost no time: nothing is awaited.
function save(formData) {
console.log(formData.get('name'));
}This is not a bug in the hook. When you test a pending UI locally, your fake backend responds instantly, so the pending state looks absent. Add an artificial delay while developing:
async function save(formData) {
await new Promise((resolve) => setTimeout(resolve, 1500));
console.log('Saved', formData.get('name'));
}The opposite issue is a flash. A request that takes 150 ms makes the button label flip to "Saving..." and back, which looks like flicker. Common remedies are keeping the button width fixed so the layout does not jump, or showing only a subtle change such as reduced opacity for short waits. Resist the temptation to add an artificial minimum delay in production code, because it makes the app slower for everyone.
Also check that the action returns the promise. If you start async work but do not await or return it, the action settles before the work does:
// Incorrect: the fetch is started but not awaited.
async function save(formData) {
fetch('/api/save', { method: 'POST', body: formData });
}
// Correct: pending lasts until the request completes.
async function saveCorrectly(formData) {
await fetch('/api/save', { method: 'POST', body: formData });
}Pitfall 4: wrong import path or old React version
useFormStatus comes from react-dom, not react. Other form hooks differ, and this trips people up:
| Hook | Import from |
|---|---|
| `useFormStatus` | `react-dom` |
| `useActionState` | `react` |
| `useTransition` | `react` |
If you import useFormStatus from 'react', it is undefined and calling it throws a TypeError. That failure is loud, so it is easy to fix.
An old React version is quieter. useFormStatus is part of React 19. If your project is on React 18, the export may not exist or may only exist in a canary build. Check both packages, because they must match:
npm ls react react-domIf you see 18.x, upgrade both packages together before debugging anything else. Also note that the action prop accepting functions is a React 19 feature, so on older versions the whole form-action model is missing.
Pitfall 5: forgetting that hooks need a Client Component
Hooks do not run in Server Components. A file that calls useFormStatus needs the 'use client' directive, or it must be imported by a file that already is a Client Component.
'use client';
import { useFormStatus } from 'react-dom';
export default function SubmitButton() {
const { pending } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Publishing...' : 'Publish'}
</button>
);
}The <form> itself can stay in a Server Component with a Server Action as its action. Only the small status-reading component needs the directive. Keeping the Client Component small is good practice, because it limits the JavaScript sent to the browser.
Before hydration there is no pending state
With a Server Action, the form can be submitted before the page's JavaScript has loaded. The browser then performs a normal form POST, and your hook has not run yet, so no pending UI appears. After hydration, submissions go through React and pending works. On slow connections you may see this as "pending works on my machine but not for the first click." Design for it by making sure the form still works as a plain HTML form, and do not rely on the pending state to prevent double submission before hydration.
Pitfall 6: misreading the other fields
Sometimes pending is fine, but the other fields look wrong. These are the rules:
| Field | While pending | When not pending |
|---|---|---|
| `pending` | `true` | `false` |
| `data` | The submitted `FormData` | `null` |
| `method` | `'get'` or `'post'`, from the form's `method` attribute | `'get'` (the default) |
| `action` | The function passed to `action` | `null` |
A common error is reading data without checking pending first:
import { useFormStatus } from 'react-dom';
function SubmissionNotice() {
const { pending, data, method } = useFormStatus();
if (!pending) return null;
return (
<p role="status">
Sending {data?.get('name')} with {method}...
</p>
);
}Without the early return, data.get('name') throws when data is null. Optional chaining (data?.get(...)) is a second safeguard.
Another surprise is method. A form without a method attribute reports 'get', even though a function action does not send an HTTP GET. The value comes from the form element, not from what your function does. Do not use method to decide whether data is being written.
Finally, the values describe the current submission only. When the action settles, data goes back to null. If you need the result of the action, such as validation errors or a success message, useFormStatus cannot give it to you. That is what useActionState is for.
Pitfall 7: expecting useFormStatus to work for non-form pending work
A button that does not submit a form, such as one that calls an async function through onClick, has no form action for the hook to track. For that case use useTransition:
'use client';
import { useTransition } from 'react';
export default function RefreshButton({ refresh }) {
const [isPending, startTransition] = useTransition();
return (
<button
type="button"
disabled={isPending}
onClick={() => startTransition(async () => { await refresh(); })}
>
{isPending ? 'Refreshing...' : 'Refresh'}
</button>
);
}Similarly, if the component that owns the form also needs the action's returned value, useActionState gives you isPending in that same component, with no child component required:
'use client';
import { useActionState } from 'react';
async function subscribe(previousState, formData) {
await new Promise((resolve) => setTimeout(resolve, 1000));
return { message: 'Subscribed ' + formData.get('email') };
}
export default function SubscribeForm() {
const [state, formAction, isPending] = useActionState(subscribe, { message: '' });
return (
<form action={formAction}>
<input name="email" type="email" />
<button type="submit" disabled={isPending}>Subscribe</button>
<p>{state.message}</p>
</form>
);
}Notice that useActionState is wired up differently. The form's action is the formAction it returns, not your original function, and your function receives the previous state as its first argument. If you pass the raw function to action and use isPending from the hook, isPending never changes.
A probe component for debugging
When you cannot tell which condition is failing, drop a temporary probe inside the form. It prints the whole status object on every render:
'use client';
import { useFormStatus } from 'react-dom';
export function StatusProbe() {
const status = useFormStatus();
console.log(status);
return null;
}Place <StatusProbe /> next to your submit button and submit the form. Read the output like this:
actionisnullwhile submitting. The hook does not see a function action on a parent form. Check pitfalls 1 and 2.actionis a function andpendingflips totrue, but only briefly. The hook works. Check pitfall 3.- Nothing logs at all. The component is not rendering, or it threw before the hook ran. Check imports, the React version, and the
'use client'directive. - Logs appear, but
pendingisfalseafter the first render and never changes. The first render logs the idle state. Look at renders after you submit, not just the first.
Remove the probe when you are done.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Button never disables, hook in the form's own component | Hook is not in a child of the form | Move the hook into a child component |
| Slow `onSubmit` handler, no pending UI | `onSubmit` is not a form action | Use `action={asyncFunction}` |
| `action` is a string | Native browser submission | Use a function for `action` |
| Pending flashes by or never paints | Action is fast or does not await | Await real work, add a delay when testing |
| `TypeError` when calling the hook | Imported from `react` | Import from `react-dom` |
| Hook missing or undefined | React 18 or mismatched versions | Upgrade `react` and `react-dom` to 19 together |
| Error about hooks in a Server Component | Missing `'use client'` | Add the directive to the status component |
| `data` is `null` and code throws | Read without checking `pending` | Return early if not pending |
| Need the action's result, not just pending | Wrong tool | Use `useActionState` |
Exercise
A teammate writes function ProfileForm() { const { pending } = useFormStatus(); return (<form onSubmit={save}><input name="name" /><button disabled={pending}>Save</button></form>); } and says the pending state never works. List the problems you can see and describe the corrected code.
Show answer
There are two problems. First, the hook is called in the same component that renders the form, so there is no parent form for it to read. Move the button into a child component such as SubmitButton that calls useFormStatus and render it inside the form. Second, the form uses onSubmit, which React does not track as a form action. Pass an async function to action instead, for example <form action={save}>, where save receives a FormData object and awaits the request. With both changes, pending is true until the awaited work finishes.
Exercise
A form's action is async function save(formData) { fetch('/api/save', { method: 'POST', body: formData }); }. The button flickers to "Saving..." and back almost instantly, even though the request takes two seconds. Why, and what is the fix?
Show answer
The action does not await or return the fetch promise, so the action's own promise settles right away and pending goes back to false while the request is still running. Add await before fetch (or return the promise) so pending stays true until the request completes.
Exercise
You log useFormStatus() from a probe inside a form and see action: null during submission, even though the component structure is correct. Name two causes of this.
Show answer
The form's action prop is a URL string or is missing, so the browser submits natively and React does not track it. Or the form is handled with onSubmit instead of a function passed to action. In both cases, change the form to use action={fn} with a function.
Exercise
Your form needs to show "Subscribed" after the action returns, and it also needs a disabled button while pending. Which hook is the better fit, and why?
Show answer
useActionState. It returns the action's result as state and an isPending flag in the component that owns the form, so you need no child component. useFormStatus reports only status fields (pending, data, method, action) and cannot return the action's result.