Hi I am having real difficulty getting a redux thunk action to work as expected in React Native. I have used the exact same method with an application in React which works perfectly, however cannot for the life of me work out why it does not work in my React Native application, throwing an unhandled promise rejection warning, breaking my code.
My login function is as follows:
this.props.loginUser(loginData)
.catch(err => this.setState({
errors: err.response.data.errors
}))
And has been connected to redux as follows:
export default connect(null, {loginUser})(Login)
loginUser function is as follows:
export const userLoggedIn = (user) => ({
type: LOGGED_IN,
user
})
const loginUser = (credentials) => (dispatch) =>
api.user.login(credentials)
.then(user => dispatch(userLoggedIn(user)))
export default loginUser
And POST request to server:
export default {
user: {
login: (credentials) =>
axios.post('http://10.0.0.103:3000/auth', {credentials})
.then(user => user.data.credentials)
}
}
So everything works as expected up until I try to call dispatch with the action. I have included thunk middleware which I assumed would allow all this as per my working React application, however I am getting Unhandled Promise rejection: cannot read property 'data' of undefined in this case, which confuses me.
Thanks for any help in advance