【发布时间】:2022-01-02 03:27:27
【问题描述】:
我在一个 react 本机应用程序上有一个身份验证操作,它必须在身份验证期间执行另一个操作,但它永远不会执行 (dispatch(getMobiles()))。我不理解为什么。你有什么想法吗?
如果我的身份验证顺利,我想立即检索我的新用户的数据,所以我想执行另一个操作 getMobiles()。
提前感谢:)
身份验证操作
export const authentication = (
username: String,
password: String,
label: String,
synchro: Boolean,
url: String,
) => {
return dispatch => {
dispatch({type: LOGIN.PENDING, payload: ''});
const type = UDA_URL_LIST.map(uda => {
if (uda.url === url) {
return uda.name;
}
})
.join()
.replace(/[, ]+/g, ' ')
.trim();
fetchUser(url, username.trim(), password.trim())
.then(response => {
if (!response.err) {
const newUser = {
...response,
label,
type,
synchro,
};
dispatch({type: LOGIN.SUCCESS, payload: newUser});
// not dispatched !
return dispatch(getMobiles(url, response.key, newUser.userId));
}
})
.catch(err => dispatch({type: LOGIN.ERROR, payload: err}));
};
};
getMobiles
export const getMobiles = (
url: String | null = null,
token: String,
userId: String,
) => {
return dispatch => {
dispatch({type: MOBILES.PENDING, payload: ''});
fetchMobiles(url, token)
.then(mobilesList => {
dispatch({
type: MOBILES.SUCCESS,
payload: mobilesList.data,
meta: {userId},
});
})
.catch(err => alert(err));
};
};
};
【问题讨论】:
标签: javascript reactjs react-native redux react-redux