I need to make a form to submit one of several choices and i need to use react-redux so i cannot use local state to change the choice selected
the app does work (which means componentdidmount is working) but if a select one of the choices i get TypeError: Cannot read property 'props' of undefined
componentDidMount() {
this.props.setModelSelector(data)
}
handleChange(event) {
this.props.selectCar(event.target.value)//the function doesn't get called
//this.props.setModelSelector(data)
event.preventDefault();
}
handleChange(event) {
//this.props.selectCar(event.target.value)
this.props.setModelSelector(data)//Even if i run the same function of componentDidMount i get the same error
event.preventDefault();
}
I have also checked event.target.value contains indeed the string that i need to change the value showed in the form
TypeError: Cannot read property 'props' of undefined
handleChange
src/components/ModelDetailsContainer.js:40
37 |
38 | handleChange(event) {
39 | // this.props.selectCar(event.target.value)
> 40 | this.props.setModelSelector(data)
| ^ 41 | event.preventDefault();
42 | }
43 |
thiskeyword. either solution (binding or arrow functioin) will work. And now you know :-)