听取派遣的回应

时间:2017-06-15 07:51:49

标签: reactjs redux react-redux redux-saga

在我目前的项目中,有些组件是有状态的。某些状态属性取决于调度方法的结果。

this.props.dispatch({
  type: Constants.CONTRACT_DELETE_START,
  payload: {
    contract: contract
  }
});

基本上我需要得到这样的答案,如下:

this.props.dispatch({
  type: Constants.CONTRACT_DELETE_START,
  payload: {
    contract: contract
  }
})
.catch(err => {
   this.setState({
     foo: "bar"
   });
})

是否可以在不必将foo: bar逻辑传送到Redux商店的情况下完成?

聚苯乙烯。我正在使用Redux Saga来做我的行为。

1 个答案:

答案 0 :(得分:1)

我不确定承诺的事情(如何解决或拒绝传奇中的),但您也可以这样做:

this.props.dispatch({
  type: Constants.CONTRACT_DELETE_START,
  payload: {
    contract: contract,
    callback: () => {
      // Do your stuff here
    }
  }
})

在这里传递一个回调,并根据你的逻辑在你的传奇中调用它。