skip to Main Content

Can Reactjs combine RTK query and redux for a mutation scenario?

I have created an api slice like this: export const authSlice = createApi({ reducerPath: "auth", baseQuery: fetchBaseQuery({ baseUrl: resolveApiBaseUrl(), prepareHeaders(headers) { headers.set("Content-Type", "application/json") headers.set("X-XSRF-TOKEN", <string>resolveUserToken()) return headers } }), endpoints(builder) { return { login: builder.mutation<GymAppResponse, Login>({ query: (payload) => ({…

VIEW QUESTION

onSuccess and onError not being fired in rtk query – Reactjs

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.…

VIEW QUESTION
Back To Top
Search