useActionState will replace the previous useFormState hook. When the new hook will be available in Next.js, we can start working on the Form Actions support.
And since that useActionState will work both with and without form elements, it means that probably there's no need to introduce a new hook in next-safe-action. My current idea is to update useAction and useOptimisticAction hooks to use useActionState under the hood. Action signature will change if this will be the case, since the action requires previousState to be the argument placed between optional bind params and form data, in the function called by the client.
UPDATE: implemented stateful action support in the library via stateAction instance method and useStateAction hook. Updated useOptimisticAction API too.
useAction uses React's useTransition hook under the hood.
useOptimisticAction uses React's useOptimistic hook under the hood.
useStateAction uses React's useActionState hook under the hood.
When this PR gets merged, updated documentation will be available here:
110
Please note that React's useActionState hook is available in Next.js since 14.3.0-canary version, so once the PR gets merged you are required to use a canary release. When the support for it will land in a Next.js stable version, the next branch of next-safe-action will be merged into main, and version 7 will be released with all the new features.
useActionState
will replace the previoususeFormState
hook. When the new hook will be available in Next.js, we can start working on the Form Actions support.And since thatuseActionState
will work both with and without form elements, it means that probably there's no need to introduce a new hook in next-safe-action. My current idea is to updateuseAction
anduseOptimisticAction
hooks to useuseActionState
under the hood. Action signature will change if this will be the case, since the action requirespreviousState
to be the argument placed between optional bind params and form data, in the function called by the client.UPDATE: implemented stateful action support in the library via
stateAction
instance method anduseStateAction
hook. UpdateduseOptimisticAction
API too.useAction
uses React'suseTransition
hook under the hood.useOptimisticAction
uses React'suseOptimistic
hook under the hood.useStateAction
uses React'suseActionState
hook under the hood.When this PR gets merged, updated documentation will be available here:
110
Please note that React's
useActionState
hook is available in Next.js since 14.3.0-canary version, so once the PR gets merged you are required to use a canary release. When the support for it will land in a Next.js stable version, thenext
branch of next-safe-action will be merged intomain
, and version 7 will be released with all the new features.