I have the following class snippet:
constructor(props) {
super(props);
this.timeout = null;
}
search = (e) => {
clearTimeout(this.timeout);
Are you going to make the timeout as state?
My suggestion would be like this
constructor(props) {
super(props);
this.state = {
timeout: null
}
}
search = (e) => {
clearTimeout(this.state.timeout);
const timeout = setTimeout(
function(){ console.log(e.target); },
500
);
this.setState({timeout: timeout})
}