【问题标题】:calling useMutation in a loop like useQueries in react-query在循环中调用 useMutation,如 react-query 中的 useQueries
【发布时间】:2021-01-28 14:10:35
【问题描述】:

即使我想拥有相同的功能,我也需要在 Side a 循环中调用 useMutation,在该循环中准备数据并作为有效负载发送

 aDeleteVariantData.forEach((oDeleteItem, nIndex) => {
    oDeleteVariants.mutate(oDeleteItem);
    
    // We are able to delete with axios directly but not using the mutate functionality.
    // how should achive this.
    //     delete(`/varient varientId= ${(oDeleteItem.id)}`)
     //For Each delete we have different url parameters which is not possible with the mutate
    // Is there anything like useQuries for useMutate

});

【问题讨论】:

  • 你找到解决办法了吗?

标签: reactjs react-query


【解决方案1】:

您可以通过Promise.all 使您的 mutate 函数触发许多删除请求。那时它仍然只是一个突变。

【讨论】:

  • 每次迭代的Url参数都不一样。所以每次迭代 axios 实例都会发生变化。所以需要动态创建变异函数。在 useQuries 中可以传递一个查询函数数组所以想为突变实现相同的功能
猜你喜欢
  • 2021-11-03
  • 2023-04-08
  • 2022-12-10
  • 2021-03-09
  • 1970-01-01
  • 2021-04-15
  • 2022-06-22
  • 1970-01-01
  • 2021-07-09
相关资源
最近更新 更多