T
TanStack•3y ago
adverse-sapphire

How do I show the errors in formik with useMutation

No description
3 Replies
adverse-sapphire
adverse-sapphireOP•3y ago
I`ve got this code and I am trying to display the errors from the server below the fields. In the console they are what I expect but I dont get them in the UI { "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1", "title": "One or more validation errors occurred.", "status": 400, "traceId": "00-3cada68aa471ebf583622f16a34c3b0b-684e03bfa6dba554-00", "errors": { "email": [ "Email was not found or incorrect" ] } } this is my response from the api
wise-white
wise-white•3y ago
You can pass a onError callback to the mutate function (more info in the docs: https://tanstack.com/query/latest/docs/react/reference/useMutation) and probably use Formik's setErrors method to show the error messages for the appropriate fields: https://formik.org/docs/api/formik#seterrors-fields--field-string-string---void This article may also help: https://medium.com/swlh/mapping-and-displaying-server-side-errors-with-formik-in-react-bbe7ae696895
Overview | TanStack Query Docs
React Query is often described as the missing data-fetching library for React, but in more technical terms, it makes fetching, caching, synchronizing and updating server state in your React applications a breeze. Motivation
Medium
Clean Architecture — Mapping and Displaying Server-Side Errors With...
Discussing how to properly map server-side errors to individual inputs and display the errors, which complements client-side validations…
adverse-sapphire
adverse-sapphireOP•3y ago
@julien yes, at end it is what I did and it worked. I'm still learning react query, but I love it😃...thanks

Did you find this page helpful?