Zod schema + next SSR + tanstack + additional validation #1621
Replies: 1 comment
-
I missed that the async form handlers are run in addition to the sync ones, not replacing them. Going to do a fetch for the onSubmitAsync callback which handles validating what's at the other end of a URL. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been trying to hack custom validation involving a fetch request into zod + tanstack in a next server action. My hope was that I could add additional validation to createServerValidate() in the server action so that zod would throw an error and tanstack would handle that nicely for me. I haven't been able to get it working.
I was looking through the example and here's my setup. The additional validation is to make it quick to invalidate invalid url's I'm processing and not have to pass the error back from the separate processing server to client.
I know zod 4 has
.refine(async() => {})
which I was trying to use for the fetch validation but then the zod 4 z.coerce causes ts compiler complaints. that focus is in #1626I'm using z.coerce.number() which the compiler complains about because zod 4 reads all coerced inputs as unknowns and I'm using Tanstack with that the selector as a number, but formData is always strings!
zodSchema
serverValidation.ts
serverAction.ts
Beta Was this translation helpful? Give feedback.
All reactions