【发布时间】:2017-06-09 05:07:16
【问题描述】:
我在使用 redux-thunk 时遇到问题。意思是 dispatch 不是我的动作创建者内部的一个函数,我尝试安慰返回的参数,但没有。
代码如下:
动作
export function signUp(data) {
return dispatch => {
console.log(dispatch)
if (data.email === 'email@server.com') {
dispatch(signIn(data, () => {
if (data.type === '2') {
browserHistory.push('/settings/profile')
} else {
browserHistory.push('/')
}
}))
} else {
return {
type: ActionTypes.USER_SIGN_UP__ERROR
}
}
}
}`
mapActionsToProps
const mapActionsToProps = dispatch => ({
signUp (data) {
console.log(dispatch)
dispatch(userActions.signUp(data))
}
})
顺便说一句,您可以看到我在 mapActionsToProps 中控制了调度函数,并且它按预期返回:
function (action) {
if (typeof action === 'function') {
return action(dispatch, getState, extraArgument);
}
return next(action);
}
【问题讨论】:
标签: reactjs redux react-redux redux-thunk