Sub topic 2
What useFormStatus Does and Where It Comes From
This chapter assumes you know React function components, props, and the basic hooks. It also assumes you are comfortable with HTML forms, FormData, and async functions. You do not need prior experience with React 19 form actions beyond the short recap below.
By the end you will know three things. You will know what useFormStatus returns and which package exports it. You will know which forms it can observe. You will know the mechanism that decides what its values are at any moment.
The problem it solves
Submitting a form takes time. The network call might take 300 milliseconds or 8 seconds. During that time the user needs feedback, and the form should not accept a second click on the same button.
Before React 19, the usual approach was to hold a isSubmitting flag in useState. You set it to true before the request, set it back in a finally block, and pass the flag down as a prop to every component that needed it. This works, but every form repeats the same bookkeeping, and a deeply nested button needs the flag passed through each level.
useFormStatus removes both costs. A component asks React, "Is the form I am inside currently submitting?" React answers from its own record of the submission, so you keep no state of your own and pass no props.
A quick recap of form actions
In React 19 you can pass a function to a form's action prop instead of a URL string:
<form action={saveProfile}>When the user submits, React does three things:
- It prevents the browser's default navigation.
- It builds a
FormDataobject from the form's fields. - It calls your function with that
FormData, inside a transition.
If the function is async, React treats the submission as in progress until the returned promise settles. The next chapters cover form actions in more detail. What matters here is that React itself runs the submission, so React knows when it starts and ends. useFormStatus exposes that knowledge.
What the hook is
useFormStatus is a hook that returns information about the most recent submission of the parent <form>. The signature is:
const { pending, data, method, action } = useFormStatus();It takes no arguments. You do not tell it which form to watch. It always reports on the nearest <form> that contains the component calling it.
Where it comes from
The hook is exported from react-dom, not from react:
import { useFormStatus } from 'react-dom';This surprises many people, because almost every other hook lives in react. The reason is that forms are a DOM concept. The react package holds renderer-independent features like state, effects, and context. react-dom holds things tied to browser elements such as <form>, portals, and flushSync. The hook reports on a DOM form, so it belongs with the DOM renderer.
Compare it with its neighbor useActionState, which comes from react:
| Hook | Import | Where it is called | What it gives you |
|---|---|---|---|
| `useFormStatus` | `react-dom` | A child of the `<form>` | `pending`, `data`, `method`, `action` of the parent form |
| `useActionState` | `react` | The component that owns the action | The action's last returned state, a wrapped action, and `isPending` |
A wrong import is the most common first error. If you write import { useFormStatus } from 'react', the import is undefined, and the call fails with an error such as "useFormStatus is not a function".
Version requirements
useFormStatus is stable in React 19 and react-dom 19. Older canary builds exposed it under the name experimental_useFormStatus, which you may see in older articles. Check your installed versions before debugging anything else:
npm ls react react-domBoth packages should report a 19.x version. A mismatch, such as react at 19 and react-dom at 18, is a frequent cause of "not a function" errors.
The returned object
The hook returns one object with four fields.
| Field | Type | Meaning |
|---|---|---|
| `pending` | `boolean` | `true` while the parent form's action is running, otherwise `false` |
| `data` | `FormData` or `null` | The data being submitted, or `null` when nothing is pending |
| `method` | `'get'`, `'post'`, or `null` | The HTTP method declared on the parent form |
| `action` | function or `null` | The function passed to the parent form's `action` prop |
If there is no parent form, pending is false and the other three are null. The same is true when the form has not been submitted yet. Later chapters examine data, method, and action in detail. For now, treat pending as the main field and the other three as extra context.
A first working example
This is the smallest useful case. It has two components. ProfileForm owns the form, and SubmitButton sits inside it.
'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 ProfileForm() {
async function saveProfile(formData) {
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log('Saved', formData.get('name'));
}
return (
<form action={saveProfile}>
<input name="name" placeholder="Name" />
<SubmitButton />
</form>
);
}Here is what happens when the user types a name and clicks Save:
- React calls
saveProfilewith aFormDatacontaining thenamefield. - React marks the parent form as pending.
SubmitButtonre-renders.pendingis nowtrue, so the button is disabled and reads "Saving...".- After one second the promise resolves and React marks the form as no longer pending.
SubmitButtonre-renders withpendingasfalse.
Notice that ProfileForm contains no useState and no try/finally. The button reads the status itself.
The 'use client' line at the top matters in frameworks that support Server Components, such as Next.js. Hooks only run in Client Components. In a plain client-side React app the line has no effect and is harmless.
How the timing works
The sequence below shows the order of events between the user, the form, your action, and the button.
The status flows from the form down to the button, not from your action to the button. Your action function never calls anything related to the status. This is why the hook needs no setup code in the action.
Why it reads the parent form
Conceptually, useFormStatus behaves like a context consumer. Each <form> with a function action publishes its status to the components rendered inside it. The hook reads the nearest published status, in the same way useContext reads the nearest provider.
You do not create this provider. React's <form> implementation supplies it. The practical consequences are the same as for any context lookup:
- The component must be rendered inside the form's subtree. A button three levels down still works.
- The nearest form wins. If one form is nested inside another through a component boundary, the hook reports the inner form.
- A component outside any form sees the "not submitting" values.
This explains the rule that the next chapters examine at length: calling the hook in the same component that renders the <form> does not work. That component sits above the form it creates, not inside it, so no status is published to it.
import { useFormStatus } from 'react-dom';
// Incorrect: the hook runs in the same component that renders the form,
// so it does not read this form's status and pending stays false.
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, exactly as SubmitButton does in the working example.
Which submissions it tracks
The hook tracks submissions that React handles. In practice that means a <form> whose action prop is a function. If you pass a URL string, or no action at all, the browser performs a normal navigation. React is not running the submission, so there is no pending state to report, and action in the returned object is null.
The same applies to buttons that override the form action. A <button formAction={fn}> also works with a function. In that case the status relates to the submission that button started.
Here is a table of common setups and what you can expect:
| Form setup | Does `pending` become `true`? |
|---|---|
| `<form action={asyncFunction}>` with the hook in a child | Yes, until the promise settles |
| `<form action={syncFunction}>` with the hook in a child | Only for a very short time, because there is no promise to wait for |
| `<form action="/submit">` | No, the browser navigates instead |
| `<form onSubmit={handler}>` with no `action` | No, React is not managing the submission |
| Hook called in the component that renders the form | No, the hook cannot see that form |
The synchronous case deserves a note. The function runs inside a transition, so the pending state may last only one render. The user will not notice it. This is fine: the pending UI only matters for work that takes time.
Reading the other fields
You will mostly use pending, but here is a short component that shows all the fields working together. It renders only while a submission is running.
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>
);
}Two details are worth noting. First, data is null when no submission is pending, so the component checks pending first and uses optional chaining as a second guard. Second, method reflects what the form declares. A form with no method attribute reports 'get', which is the HTML default, even though React handles the submission itself. The value describes the form's declared method, not a request React actually sends.
What the hook does not do
Keeping the limits clear prevents wasted debugging time.
- It does not return the result of the action. If the action fetches data or validates input and you need to show an error or a success message, use
useActionState. That hook is the subject of a later chapter. - It does not run or cancel the submission. It is read-only. You cannot call it to start or stop anything.
- It does not accept a form reference. You cannot point it at a form in another part of the page.
- It does not report on a form you created but have not yet submitted. Before the first submission,
pendingisfalseanddataisnull. - It does not work in Server Components. Hooks need a Client Component. Server-rendered forms can still use it through a small client child.
Common first errors and what causes them
| Symptom | Likely cause | Fix |
|---|---|---|
| `useFormStatus is not a function` | Imported from `react` instead of `react-dom`, or `react-dom` is older than 19 | Import from `react-dom` and check versions |
| `pending` is always `false` | Hook called in the component that renders the form | Move the hook into a child component |
| `pending` is always `false` | Form uses `action="/url"` or `onSubmit` | Pass a function to `action` |
| Hook error about hooks in a Server Component | Missing `'use client'` in the file | Add the directive to the component file |
| `pending` flickers and ends at once | The action is synchronous | Expected, as there is nothing to wait for |
Most of these come down to one question: does React know it is running this submission, and is the hook inside the form? If both answers are yes, pending will work.
Summary
useFormStatus is a hook from react-dom that returns { pending, data, method, action } for the nearest parent <form>. It takes no arguments and reads status that the form publishes when its action is a function. You call it in a child component of the form, because the form cannot publish status to the component that creates it. It reports on a submission and does not return the action's result.
Exercise
A teammate writes the component below. The Save button never disables during submission. Name two separate problems that could be causing this, and say how you would fix each. import { useFormStatus } from 'react'; export default function SignupForm({ onSubmit }) { const { pending } = useFormStatus(); return ( <form onSubmit={onSubmit}> <input name="email" /> <button type="submit" disabled={pending}>Save</button> </form> ); }
Show answer
There are three problems, and any two answer the question. First, the hook is imported from 'react' but it is exported from 'react-dom', so the import is undefined and the call fails. Change it to import { useFormStatus } from 'react-dom'. Second, the hook is called in the same component that renders the form, so it is not inside the form and cannot read its status. Move the button into a child component such as SubmitButton and call the hook there. Third, the form uses onSubmit rather than a function passed to the action prop, so React does not manage the submission and publishes no pending status. Pass an action function to the form, for example action={signup}, where signup receives a FormData object.
Exercise
What values does useFormStatus return for a component rendered before any submission has happened, and which of the four fields would you check first before reading data safely?
Show answer
Before any submission, pending is false and data, method, and action are null. When you read data, check pending first, because data is only a FormData object while a submission is pending. Optional chaining such as data?.get('name') adds a second guard.