Reactjs 在then()函数中调用另一个端点可以吗?Axios反应器

Reactjs 在then()函数中调用另一个端点可以吗?Axios反应器,reactjs,ecmascript-6,react-redux,axios,Reactjs,Ecmascript 6,React Redux,Axios,我是React js的新手,我对我的端点有疑问。 在.then()函数中调用另一个端点可以吗? 这是我的密码: this.props.getReviwerSurvey(surveyId, authToken.id) .then( () => { const { reviewerSurvey } = this.state; this.props.getAccount(reviewerSurvey && reviewerSur

我是React js的新手,我对我的端点有疑问。 在.then()函数中调用另一个端点可以吗? 这是我的密码:

this.props.getReviwerSurvey(surveyId, authToken.id)
  .then(
    () => {
      const {
        reviewerSurvey } = this.state;
      this.props.getAccount(reviewerSurvey && reviewerSurvey.relationships ?
      reviewerSurvey.relationships.participant.id : null);

    },
  );

this.props.getReviewerSurvey是我的第一个端点,而我的第二个端点this.props.getAccount()似乎不是标准的。如何在不调用回调中的this.props.getAccount的情况下获取reviewerSurvey.relationships.participant.id的值?如果还有别的办法。非常感谢您的想法。

您可以从第一个请求返回已解决的承诺,然后将其传递到下一个
链,这样您将避免回调地狱

一些一般性的例子:

this.props.getReviwerSurvey(surveyId, authToken.id)
  .then(() => {
      const { reviewerSurvey } = this.state;
      return reviewerSurvey;
    },
  ).then((reviewerSurvey) => {
     return this.props.getAccount(reviewerSurvey && reviewerSurvey.relationships ?
      reviewerSurvey.relationships.participant.id : null);
  }).then((participantId) => {
      // do something with participantId or other data related to the account
  });

好的,我试试这个主意。谢谢