Here's the code
import React, { Component, useImperativeHandle } from 'react';
class SearchBar extends Component {
render() {
return <input onChange={this.onInputChange} />;
}
onInputChange(event) {
console.log(event)
}
}
export default SearchBar;
There's no error still on input nothing get the console logged.
You need to bind your event handler to your class component as below
import React, { Component, useImperativeHandle } from 'react';
class SearchBar extends Component {
constructor(props) {
super(props);
this.onInputChange = this.onInputChangebind(this); //You NEEDED THIS
}
render() {
return <input onChange={this.onInputChange} />;
}
onInputChange(event) {
console.log(event)
}
}
export default SearchBar;
Works on my side... i highlighted the console.log outputs as shown on picture

otherwise if you needed to see the words you typed on the input tag you can just do
console.log(event.target.value) instead of console.log(event)