【发布时间】:2017-02-26 15:23:15
【问题描述】:
我有两个 redux 操作,调用如下。
export function action1(params) {
//This line is always called.
return (dispatch) => {
//This line is not called the second time.
return MyApi.call1(params)
.then(response => {
// some logic
return dispatch(someFunction1());
})
.catch(error => {
throw(error);
});
};
}
export function action2(params) {
return (dispatch) => {
return MyApi.call2(params)
.then(response => {
// call the first API again
action1();
return dispatch(someFunction2());
})
.catch(error => {
throw(error);
});
};
}
当第一次加载视图时,action1 在视图的构造函数中被调用。在同一视图中执行操作并触发action2 时,需要在action2 成功时调用action1 以从服务器获取更新的列表。不幸的是,当第二次调用action1 时,代码会中断而没有任何错误。
我在这里错过了什么?
【问题讨论】:
-
顺便说一句,你还没有派出 action1 ,比如:
dispatch(action1(params)); -
成功了。我真是太傻了。您可以将此作为答案发布以便我接受吗?
标签: javascript reactjs react-native redux react-redux