T
TanStack10mo ago
xenial-black

Set error message from api error response

I have an api that gives you the error messages, for example "user already taken" , "user doesnt exist" , etc. I wanna set the error message for a specific field in my form. Best way to do it? I found something like this in a github discussion: onSubmit: async ({ value }) => {if (someCondition) {setFieldMeta("fieldName", (prev) => ({...prev,errorMap: {onChange: "Your error message here",},}));return;}// Rest of your submit logic}
1 Reply
xenial-black
xenial-blackOP10mo ago
To add: Im also using Zod. So technically I have 2 types of validations. The first one on the FE and the second one in. BE. I'm using tanstack query too

Did you find this page helpful?