MapStateToProps Is Not Running
I am new to react and I can't debug why mapStateToProps is not running. Pls see the last function in login.js. I have added alert statements in my mapStateToProps function but its
Solution 1:
I assume that it is mapDispatchToProps that isnt working, right? Try this
...
const mapDispatchToProps = (dispatch) => (
return {
sendTheAlert(coin) {
debugger;
alert();
return dispatch(userConstants.LOGIN_REQUEST) }
})
A sample of how to structure mapDispatchToProps would be (from https://react-redux.js.org/using-react-redux/connect-mapdispatch). Be mindful of the return statement.
const mapDispatchToProps = dispatch => {
return {
// dispatching plain actions
increment: () => dispatch({ type: 'INCREMENT' }),
decrement: () => dispatch({ type: 'DECREMENT' }),
reset: () => dispatch({ type: 'RESET' })
}
}
Solution 2:
Everything is fine I was just calling this.sendTheAlert()
wrong. it should be this.props.sendTheAlert()
Post a Comment for "MapStateToProps Is Not Running"