Only onSuccess gets fired even if error has occurred in useMutation. WHY? #6626
Replies: 2 comments
-
This code turns the error into a resolved promise
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks a lot.😌 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
//mutation hook
const { data, mutate: mutateCustomer } = useMutation({
mutationFn: createCustomer,
onSuccess: () => {
console.log("navigated")
navigate("/")
},
onError: () => {
console.log("error occured")
},
})
//api.js
//i have BASEURL
export const createCustomer = async (customerDetail) => {
try {
const { data } = await axios.post(
${BASEURL}/api/65865d8b75a727705c869123/customers/add,
customerDetail
)
toast("success", "New customer is created 😁")
return data
} catch (err) {
toast("error", err.message)
return err
}
}
if i submit with empty customer details, i get internal server error but onSuccess gets triggered and page is navigated to homepage, onError never gets triggerred...
Beta Was this translation helpful? Give feedback.
All reactions