Tiny hook around React 19's useActionState
for ergonomic server-action "mutations".
npm i @luminex/use-action-mutation
'use client';
import { useActionMutation } from '@luminex/use-action-mutation';
import { myAction } from './actions';
const { mutate, isPending, data } = useActionMutation(myAction, {
onSuccess: (s) => console.log('ok', s.response),
onError: (s, e) => console.error(e),
});
-
useActionMutation(action, { initialState, onSuccess, onError })
-
envelopeServerAction(() => Promise<T>) → { success, response? , error? }
-
ServerActionState<T>