Implementing Mulitple mutations to two different API’s using React query

const first = useMutation({
    mutationFn: (data) => {
      return Promise.all([
        (axios.put(
          "https://dummyjson.com/products/1",
          JSON.stringify({
            title: "iPhone Galaxy +1",
          })
        ),
        axios.post(
          "https://reqres.in/api/users",
          JSON.stringify({
            name: "morpheus",
            job: "leader",
          })
        )),
      ]);
    },
    onSuccess: (data) => {
      console.log(data);
    },

    onError: (error) => {
      console.log(error);
    },
  });


actually I want to perform two post requests to two different apis but the useMutation is posting only to the one api

In the above code only the second promise is resolved and the first one not getting resolved


Expected output:
Both promises should be resolved and give the response from both the apis

Leave a Comment