【发布时间】:2021-04-01 07:55:41
【问题描述】:
我是 React-Redux 的新手!
但我有一个问题。
内部函数(async dispatch)如何接收dispatch()参数?
GetCurrentUserInfoAction Creator 函数:
export const getCurrentUserInfo = () => async dispatch => {
const response = await axios.get('/api/users/me')
dispatch({
type: userActions.SET_CURRENT_USER_INFO,
users: response.data.data
})
return response.data.data
}
getCurrentUserInfo 的调用方式:
export const AuthGuard = connect(
state => ({
currentUserSlug: state.session.currentUser
}),
dispatch => ({
authOrRedirect: () => {
return dispatch(getCurrentUserInfo()).catch(() => {
history.replace('/login')
})
}
})
)(AuthGuardComponent)
getCurrentUserInfo()没有收到任何参数,是不是因为被dispatch(getCurrentUserInfo())包围了?
【问题讨论】:
标签: javascript reactjs react-redux