I have a custom useMutation
hook:
const {
status: updateScheduleStatus,
reset: updateScheduleReset,
mutateAsync: updateSchedule,
} = useUpdateSchedule(queryClient, jobId as string);
Which I understand sets up the mutation but how would I use this if I wanted to do multiple parallel mutations?
I have tried to implement the following but the mutations execute prior to getting to the Promise.all(mutations
line.
let mutations: Array<any> = [];
schedulesForDeletion.forEach(async (schedule) => {
const resp = await monitoringService?.getSchedule(
schedule.schedule_id,
);
mutations.push(
updateSchedule({
monitoringService: monitoringService as MonitoringServiceClient,
schedule,
etag: resp?.type === "data" ? resp.headers.etag : "",
}),
);
});
console.dir(mutations);
await Promise.all(mutations);
I would have through that as mutateAsync
returns a Promise
that they would not fire in sequence but seems that they do.
Is there a way to handle this in react-query
or am I better off just performing this with axios? It would be useful to do in react-query
as I need to invalidate some queries when the mutations are successful.