我有两个 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
同一视图中执行操作并触发后,action1
需要调用 onaction2
的成功才能从服务器获取更新的列表。不幸的是,代码action1
在第二次调用时没有任何错误。
我在这里想念什么?
您尚未发送action1
.
dispatch( action1( params ) )
action1()
不调用dispatch
就返回一个函数。为了获得dispatch
返回的函数,您应该使用dispatch
该函数。然后它会被redux-thunk
中间件捕获。中间件将传递dispatch
并调用函数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句