React Foundations · Actions & Forms

Knowing when a form is submitting

useFormStatus

Knowing when a form is submitting

An async form action takes time, and the person filling in the form deserves to know it is working. useFormStatus reads the status of the enclosing form from a child component, with no prop threaded down:

import { useFormStatus } from 'react-dom';

function SubmitButton() {
  const { pending } = useFormStatus();
  return <button disabled={pending}>{pending ? 'Saving…' : 'Save'}</button>;
}

It returns pending, plus the form's data, method, and action. pending is true from the moment the action starts until it settles, including while an async action awaits a server response.

The key rule: a component that calls useFormStatus must be rendered inside the <form>, so it can read that form's status. The component that owns the form does not see it, because the status belongs to the <form> element the child is rendered within:

<form action={save}>
  <SubmitButton />
</form>

Your job is to show a pending label from a button inside a form in App.jsx.

Challenge

A submit button looks idle while the form is still working. Export an App component from App.jsx that renders a <form> with an async action and, inside it, a submit button. The button reads useFormStatus and shows Submitting… while the form is pending, and Save otherwise.

The Test submits the form, expects the button to read Submitting… while the action runs, then expects it back at Save. The starter always reads Save, so the Test fails.

App.jsx
export function App() {
  return (
    <form aria-label="Save">
      <button type="submit">Save</button>
    </form>
  );
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.