score:3

Accepted answer

the solution is writing

onchange={() => {console.log("hello")}}

why does it work like that? onchange get an event handler, which is a function, to execute when the onchange event happens. you didn't give the onchange a function, u just gave it a block.

a better solution would be:

const handleonchangeevent = () => {
  console.log("hello")
}

onchange={handleonchangeevent}

btw, in your render function, i would change the

this.props.data != null 

to:

this.props.data !== null 

read about === in javascript.

score:0

for that event to work you would need to bind it.

try it this way:

onchange={() => console.log("hello")}

you can also find more information on how to handle events on react


Related Query

More Query from same tag