this.props.authState
stays the same although I'm dispatching an action in my componentDidMount
function:
componentDidMount() {
if (localStorage.getItem('token')) {
dispatch(updateAuthState('AUTHENTICATED'));
}
}
render() {
<div>{this.props.authState}</div>
}
Home.propTypes = {
authState: PropTypes.string
};
const mapStateToProps = (state) => {
return {
authState: state.authState
}
};
const mapDispatchToProps = (dispatch) => {
return {
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Home);
the output is NO_AUTH (the initial value of authState
)
Reducer:
export function authState(state = "NO_AUTH", action) {
switch (action.type) {
case 'AUTH_STATE':
return action.authState;
default:
return state;
}
}
any idea why?