state is undefined in useFormState with server actions
Unanswered
Peterbald posted this in #help-forum
PeterbaldOP
basically I have a client component like this
and I’m using <Form action={…}>…</Form> in some other server components
There are no errors anywhere whatsoever, I tested with a console.log in the server action before the
Another behaviour is that the state only updates to undefined once… if I press submit multiple times it doesn’t log ever again. Not sure if this helps?
'use client';
import { useFormState } from "react-dom";
export default Form({ action, children }: SomeTypeHere) {
const [state, formAction] = useFormState(action, { message: '' });
console.log(state);
return (
<form action={formAction}>
{children}
</form>
);
}and I’m using <Form action={…}>…</Form> in some other server components
There are no errors anywhere whatsoever, I tested with a console.log in the server action before the
return { … } statement and it does log properly, but despite returning a valid message string the state shows up as undefined in the browser console (??) (the initial state logs properly, it’s just that when I submit the form the state becomes undefined)Another behaviour is that the state only updates to undefined once… if I press submit multiple times it doesn’t log ever again. Not sure if this helps?
4 Replies
PeterbaldOP
help?
PeterbaldOP
i just tried the exact example from https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations
and it doesn't work
Giant panda
I have the same issue, It was working a while ago but it just stopped suddenly