我有一个自定义useMutation
钩子:
const {
status: updateScheduleStatus,
reset: updateScheduleReset,
mutateAsync: updateSchedule,
} = useUpdateSchedule(queryClient, jobId as string);
我知道设置了突变,但是如果我想做多个并行突变,我将如何使用它?
我试图实现以下内容,但突变在到达Promise.all(mutations
生产线之前执行。
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);
我会通过它作为mutateAsync
回报Promise
,他们不会按顺序触发,但似乎确实如此。
有没有办法处理这个问题,react-query
或者我最好用 axios 执行这个?这样做很有用,react-query
因为当突变成功时我需要使一些查询无效。