Question presented to candidate:
"Why does useFormStatus only work in a child of the form, and not in the component that renders it?"
What a strong answer should cover:
- It reads the submission status of the nearest form above it — returning
{ pending, data, method, action }— without being passed anything. - The "must be a child" rule is not arbitrary: it reads a context the
<form>element provides, and a component does not sit inside the context it renders. Calling it beside the form returnspending: falseforever, silently. - It exists to solve prop drilling for a design-system component. A shared
<SubmitButton>can show a spinner in any form without every form having to pass apendingprop. - It comes from
react-dom, notreact, because it is DOM-specific — it is about a form element in the DOM. datais the submitted FormData, which lets the button show what is being saved.- It is read-only: it reports status, it does not start or control the submission.
- Compare with
useActionState, which gives you the pending flag for an action you defined, in the component that defined it.
Clarifying questions expected:
- "Is the button a shared component, or local to this one form?" — local buttons can just take a prop.
- "Do we already have
useActionStatehere?" — thenisPendingmay already be in scope.
Code / implementation expected: Optional. A <SubmitButton> used inside two different forms makes the point immediately.