TanStackT
TanStack10mo ago
6 replies
brilliant-lime

Handling zod and backend errors

Assume, there is a form-level validation for fields - this is zod. Another validation happens during submit - backend API can return submission errors, e.g. "username taken".

How can I store and handle those backend errors? I was thinking useState with backend errors which are returned in another form-level validator. However, having any errors in the form will block submission (canSubmit is then false and onSubmit won't be triggered).

Am I missing any obvious solution? Beside clearing each field backend errors on change - I would prefer to handle it on form level instead of pushing listeners to each field.
Was this page helpful?