React 19 introduces the useActionState hook:
useActionStateallows to execute any sync/async action while giving access to the action status (pending) and state (e.g. errors).
It's ideal to execute any action (even async) in response to submitting a form. But it can also be used with any payload, not only forms and FormData.
useActionEffect is a wrapper on useActionState using effect:
- Accept any generic
Payload - Execute any
Effectwith all dependencies included (extracted fromCustomRuntime) - Report errors or success data inside the state of
useActionState
The return type is the same as
useActionState, so you can swap the two hooks without breaking other parts of the code.
The useInsertUser hook in the example snippet shows how to make a POST request with @effect/platform passing the FormData as body:
- Specific the type of payload as
FormData datareturn type inferred from the returned value in theEffect