Next js server actions with tanstack form and zod
I've been looking at the tanstack form validation with the zod schema. I've followed the documentation and made a client side component with zod and everything works great.
Now i've been looking at the Next Server Actions example https://tanstack.com/form/latest/docs/framework/react/examples/next-server-actions?path=examples%2Freact%2Fnext-server-actions%2Fsrc%2Fapp%2Fclient-component.tsx
And if I try that it works fine as well, however when I try to add the zodSchema validator the formErrors that were previously undefined now give a Record<string, StandardSchemaV1Issue[]> | undefined)[] from zod. It is unclear to me how I now would throw/show the right errors in this case. And is it possible in the action.ts to use the zod schema as well instead of using onServerValidate and then throw custom errors in case someone somehow passed the client side validation?
React TanStack Form Next Server Actions Example | TanStack Form Docs
An example showing how to implement Next Server Actions in React using TanStack Form.
5 Replies
conscious-sapphire•6mo ago
in the client component there is this mergeForm thing which should take the errors returned by teh server action and integrate it into the form. It is working for me, isn't this working for you?

conscious-sapphire•6mo ago
it should then display errors here

conscious-sapphire•6mo ago
and this is where the actual form errors are returned from the server side

rival-blackOP•6mo ago
Yeah i'm aware but i meant if i add the
validators: {
onChange: zodSchema
}
in the useform below the transform part then that <p key={error as unknown as string}>{error}</p> doesn't work anymore it will throw errors once you try to type something
So this
does not work (ignore that it doesn't show the field and buttons the text was too long
that would be the rest
compatible-crimson•5mo ago
we're you able to resolve this @Espy ?