setErrors not working with server side errors.
I am trying feltejs for the first time. all is working. but I am not able to figure out how setErrros work with server-side errors.
const { form, errors, setFields, setErrors } = createForm({ onSubmit: async (values) => { console.log('values', values); postData(values); } // extend: validator({ schema }) });
post Request
const postData = (values) => { axios .post('plans', JSON.stringify(values), { headers: { 'Content-Type': 'application/json' } }) .then((response) => { console.log('response', response); if (response.status == 201) { navigate('/a/plans/'); } }) .catch((error) => { const httpError = HandleHttpErrors(error); setErrors(httpError); console.log('httpErrors', httpErrors().title); }); } };
can anyone please explain what I am doing wrong?
You don't need to use setErrors to handle server side errors. You can use the onError callback on the configuration object.
thank you