Redux Toolkit Query . How to use on mutation result and call multiple mutations based on first mutation result

Viewed 9

I started implementingRedux-toolkit-query, Now I need to call the ist mutation to pass _id, the first mutation returns some data based on that result I need to call other Api's parallel. How can I implement that using RTK? Here I have three Endpoints based on first end point getBrand, I need to call the other two endpoints.

const brandSlice = apiSlice.injectEndpoints({
  endpoints: (builder) => ({
    getBrand: builder.mutation({
      query: (body) => ({
        url: URL.GET_BRAND,
        method: "POST",
        body: body,
        responseHandler: (response) => response.json(),
        validateStatus: (response, result) =>
          response.status === 200 && result.success === 1,
      }),
      transformResponse: (response) => {
        return response.data;
      },
    }),
    getMenu: builder.mutation({
      query: (body) => ({
        url: URL.GET_BRAND,
        method: "POST",
        body: body,
        responseHandler: (response) => response.json(),
        validateStatus: (response, result) =>
          response.status === 200 && result.success === 1,
      }),
    }),
    getServices: builder.mutation({
      query: (body) => ({
        url: URL.GET_SERVICES,
        method: "POST",
        body: body,
        responseHandler: (response) => response.json(),
        validateStatus: (response, result) =>
          response.status === 200 && result.success === 1,
      }),
    }),
   
      
  }),
});
0 Answers
Related