【发布时间】:2018-05-28 20:38:52
【问题描述】:
我想从另一个动作中分派一个动作,但不能这样做。当我尝试这样做时,它无法找到 getAllUser 方法。
下面是我的动作课。
export const myActions = {
getAllUser() {
return (dispatch) => {
makeApiCall()
.then((response) => {
dispatch({
type: USER_SUCCESS,
payload: response,
});
})
.catch((error) => {
dispatch({
type: USER_FAILURE,
payload: error,
});
});
};
},
addUser(user) {
return (dispatch) => {
makeApiCall(user)
.then((response) => {
/*
Need help here :
wants to call above getAllUser()
.then(() =>
dispatch({
type: ADD_SUCCESS,
payload: response,
});
)
*/
};
},
};
我尝试了各种方法,例如,
myActions.getAllUser()
.then((response) =>
dispatch({
type: ADD_SUCCESS,
payload: response,
});
);
并尝试直接调度,
const self = this;
dispatch(self.getAllUser());
dispatch({
type: ADD_SUCCESS,
payload: response,
});
解决此问题的另一种方法是在addUser 成功之后更新reducer,而不是再次从UI 调用getAccount 以刷新结果,但只是想知道如何使用多次调度来实现这一点。
【问题讨论】:
标签: redux react-redux