TanStackT
TanStack14mo ago
1 reply
endless-jade

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}
Was this page helpful?