Reactjs 使用axios递归链接axios调用

Reactjs 使用axios递归链接axios调用,reactjs,redux,react-redux,axios,redux-saga,Reactjs,Redux,React Redux,Axios,Redux Saga,我正在阅读XML文档中的行,并使用axios将它们发送到api。我希望递归地逐行发送并链接此请求(从第一行获得成功后再发送第二行)。 我在React项目中使用了Redux、Redux saga和axios。 我在我的组件中创建了递归函数,并在reducer中创建了sendStatus字段。此sendStatus有3个字段(成功、失败、发送) 发送-我再次调用函数 成功-我正在发送新行和增量索引 失败或array.length>index i停止函数。 但是它把所有的行发送到一起,我同时得到所有成

我正在阅读XML文档中的行,并使用axios将它们发送到api。我希望递归地逐行发送并链接此请求(从第一行获得成功后再发送第二行)。 我在React项目中使用了Redux、Redux saga和axios。 我在我的组件中创建了递归函数,并在reducer中创建了
sendStatus
字段。此sendStatus有3个字段(成功、失败、发送)

  • 发送-我再次调用函数
  • 成功-我正在发送新行和增量索引
  • 失败或array.length>index i停止函数。 但是它把所有的行发送到一起,我同时得到所有成功的有效载荷
  • 我想在我的传奇中创建递归发送。但是我不知道怎么做

    下面是我在组件kargo.tsx中的函数

        sendedIndex = 0
        const handleFileUpload = () => {
        sendedIndex = 0;
        sendGood(goods[sendedIndex]);
        sendedIndex++;
        setAlert({ ...alert, showUploadButton: false });
        recursiveSending();
      };
    
      const recursiveSending = () => {
        const { failed, sending, success } = kargo.sendingStatus;
        if (failed) {
          setAlert({ ...alert, sendingError: lang.errorDuringsending });
        } else if (goods.length - 1 < sendedIndex) {
          toast.success(lang.sendedSuccesfull);
        } else if (sending) {
          recursiveSending();
        } else if (success) {
          sendGood(goods[sendedIndex]);
          sendedIndex++;
          recursiveSending();
        }
      };
    
    这是我的传奇

    export function* KargoSaga() {
      yield takeEvery(KargoActions.sendGood, bindAsyncActions(KargoActions.sendGoodAsync)(kargoApi.sendGood));
    }
    
    还有我的kargo.api.ts

    export default class KargoApi {
      static sendGood = (data: any) => {
        return axios.post(`/cargo`, data).then(({ data }) => data);
      };
    }
    
    export default class KargoApi {
      static sendGood = (data: any) => {
        return axios.post(`/cargo`, data).then(({ data }) => data);
      };
    }