It looks like I am supposed to be able to map my dispatch handling functions onto the props of a connected component (in my example List) through the typically named mapDispatchToProps function. In my List component I am confused as to why this.props.a is undefined?
ListContainer.jsx
const mapStateToProps = state => {
return {
list: state.list
}
}
const mapDispatchToProps = dispatch => {
return {
a: () => {} //simple function just for testing
//onDelete: (id) => {
// dispatch(actionCreators.delete(id));
//}
}
}
const ListContainer = connect(
mapStateToProps,
mapDispatchToProps
)(List);
module.exports = ListContainer;
List.jsx
module.exports = class List extends Component {
render() {
let list = this.props.list; //the list is on props as expected
alert(JSON.stringify(this.props)); //function a is not on props
...
return ...
}
}
Versions: "react": "^16.0.0", "react-redux": "^5.0.6", "redux": "^3.7.2",
JSON.stringifydoes not show the functions in the object. Therefore you dont seethis.props.afunction. Simply callthis.props.afunction to test. - Prakash Sharmanullinstead mapDispatchToProps toconnectfunction - Alexey Nikonov