const [login] = useLoginMutation({
onSuccess: () => {
console.log("Success");
setAlertType("success");
setAlertMessage("Login successful!");
setOpenAlert(true);
},
onError: (error) => {
console.log("Error: " + error);
setAlertType("error");
setAlertMessage(`Login failed: ${error}`);
setOpenAlert(true);
}
});
Everything is working except that the onSuccess and onError doesn’t fire. The query is successful and everything.
2
Answers
}
onSuccess
andonError
are not options in RTK Query.You can not just make up options and expect them to work. Maybe you confused that with options from another library?
Generally, the hooks do not have any lifecycle callbacks. You can defined lifecycle callbacks (different ones, with different names) on endpoint level, but not on component/hook level.