Question presented to candidate: "Build me a form in React 19 with validation errors, a disabled button while saving, and a shared submit component. Which hooks, and where does each go?"
What a strong answer should cover:
- The two hooks answer different questions from different positions in the tree — that is the whole selection rule.
useActionStatesits where the action is defined: it owns the returned state (result and validation errors) and gives youisPendingthere.useFormStatussits inside the form, in a component that was passed nothing: it reads{ pending, data, method, action }from the nearest form above.- They compose — one
useActionStateat the form level for the result, and any number of descendants readinguseFormStatus. - Package matters:
useActionStatefromreact,useFormStatusfromreact-dom. - Most fields should be uncontrolled; control only the ones needing per-keystroke behaviour.
- Errors are returned from the action as state, not thrown, so the form stays on screen — and the submitted values come back with them so nothing is lost.
- Remember React resets an uncontrolled form on success, so a field that must survive needs its value fed back or controlled.
Clarifying questions expected:
- "Is the submit button shared across forms, or specific to this one?" — that decides whether
useFormStatusearns its place. - "Do any fields need live validation?" — those stay controlled.
Code / implementation expected: Yes — a small end-to-end form is the natural answer here.