score:0

your function is getting called but since it is not bound, it is not able to recognize the state object because of which undefined object error is thrown while trying to access this.state

a normal function has this context of its own.

you can either bind the function in the constructor or use an arrow function which does not have any context of its own.

solution 1

bind your function

constructor(props) {
  super(props);
  this.handlechange = this.handlechange.bind(this);
}

handlechange(event) {
 // your code here
}

solution 2

change the function to arrow function

handlechange = (event) => {
 // your code here
}

you can also find the solution with the code provided by you in the below-codesandbox link.

edit reverent-star-5uktu


Related Query

More Query from same tag