Build useActionState and form actions from scratch: a sequential queue, pending state, errors and form reset
Problem
React 19 turned forms into a data flow: <form action={fn}> calls fn(formData) inside a transition, useActionState keeps the result of the last action, and useFormStatus lets a submit button inside the form know that it is pending. Interviewers now ask how this works underneath: what happens when the user submits twice, which state the second action sees, and where errors go. Rebuild the three pieces in user land.
const [state, dispatch, isPending] = useActionState(addTodo, { todos: [], error: null });
<Form action={dispatch}>
<input name="title" />
<SubmitButton /> {/* reads useFormStatus().pending */}
</Form>Ref. UR-1434 · © UIRound · uiround.com/questions/build-useactionstate-and-form-actions-from-scratch-a-sequential-queue-pending-state-errors-and-form-reset
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 6
- edge cases
- 5
- follow-up questions
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1Calls to
dispatchcan arrive while an action is still running. Where do they wait, and what state does the next action receive aspreviousState?
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.