Skip to content

dev48v/useactionstate-lab

Repository files navigation

⚛ useActionState Lab — React 19 form actions, made visible

An interactive React 19 lab that turns the new form action APIs into something you can watch: useActionState, useFormStatus, and the (prevState, formData) => nextState accumulator — with the exact code beside each demo.

▶ Live: https://useactionstate-lab.vercel.app/

React 19 reframed forms as a small state machine. Instead of wiring up a loading boolean, a try/catch, and a result state by hand, you give a <form> an action and React tracks pending, errors, and the returned state for you. This lab shows all three moving parts.

The three demos

  1. useActionState — the state machine. Submit a form; the action validates, awaits a fake API, and returns the next state. Watch the lifecycle strip go idle → submitting → success/error, the state JSON update to the action's return value, and a transition log record every isPending flip. No loading boolean anywhere.

  2. useFormStatus — pending without prop drilling. A <Submit> child and a spinner read the parent form's pending state directly — the form passes them nothing. Includes the one gotcha that trips everyone: the hook only works from a component rendered inside the <form>; call it in the same component that renders the form and you always get pending: false.

  3. The accumulator. useActionState is useReducer for forms: the action's first argument is the previous return value, so each submit builds on the last — plus a built-in pending flag useReducer doesn't give you.

Everything is the real React 19 API (useActionState from react, useFormStatus from react-dom) running client-side — no server required to see the mechanism.

Stack

React 19 · TypeScript · Vite.

Run locally

npm install
npm run dev

License

MIT © 2026 dev48vdev48v.infy.uk

About

Interactive React 19 lab for form actions — useActionState as a reducer with built-in pending, useFormStatus with no prop drilling, and the (prevState, formData) => nextState accumulator. Every transition made visible, code beside each demo.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors