this.props.authState stays the same although I\'m dispatching an action in my componentDidMount function:
componentDidMount() {
You're currently dispatching directly inside the componentDidMount which isn't mapped into:
connect(mapStateToProps, mapDispatchToProps)(Home);
This should do the job:
componentDidMount() {
if (localStorage.getItem('token')) {
this.props.onUpdateAuthState('AUTHENTICATED');
}
}
const mapDispatchToProps = (dispatch) => {
return {
onUpdateAuthState: function(authState) {
dispatch(updateAuthState(authState));
}
}
};
Now, this will get the authState:
const mapStateToProps = (state) => {
return {
authState: state.authState
}
};