在React Native中调度redux thunk操作时出现未处理的Promise问题

时间:2018-08-30 11:19:35

标签: reactjs react-native redux react-redux redux-thunk

嗨,我很难让Redux thunk动作按预期在React Native中工作。我已经在React中的应用程序上使用了完全相同的方法,该方法可以正常工作,但是我一生都无法弄清为什么它在我的React Native应用程序中不起作用,抛出未处理的Promise拒绝警告,破坏了我的代码。

我的登录功能如下:

undefined

并已按如下所示连接到redux:

this.props.loginUser(loginData)
            .catch(err => this.setState({
                errors: err.response.data.errors
            }))

loginUser函数如下:

export default connect(null, {loginUser})(Login)

然后向服务器发送POST请求:

export const userLoggedIn = (user) => ({
    type: LOGGED_IN,
    user
})

const loginUser = (credentials) => (dispatch) =>
    api.user.login(credentials)
        .then(user => dispatch(userLoggedIn(user)))

export default loginUser

所以一切正常,直到我尝试用该动作调用dispatch为止。我已经包含了笨拙的中间件,我认为该中间件可以按照我的React应用程序的要求进行所有操作,但是我得到了Unhandled Promise拒绝:在这种情况下无法读取未定义的属性“ data”,这使我感到困惑。

非常感谢您提前提供帮助

0 个答案:

没有答案