2
我有两个按以下方式调用的redux操作。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
时代码没有任何错误。
我在这里错过了什么?
btw,你还没有调度action1,如:'dispatch(action1(params))'; –
它的工作。这对我来说太蠢了。你可以发布这个答案,以便我可以接受吗? –