0

Hey guys i'm trying to get debounce to work with a text search field but I am unable to click and enter text into the field. I am able to enter text into the field and search when removing debounce from the constructor.

Heres where I am using debounce.

constructor() {
 this.myDebouncer = debounce(this.myDebouncer.bind(this), 1000);

state = {
    value: '',
 }
}

myDebouncer(event){
    this.setState({
    value: event.target.value
    )}
}

render(){
    onChange={this.props.myDebouncer.bind(this)}
}

Any ideas where I am going wrong? Thanks

Phil C
  • 15
  • 1
  • 4
  • Its not part of the `props`, just `this.props.myDebouncer` – Jonas Wilms Nov 30 '18 at 18:13
  • 1
    `this.props.myDebouncer.bind(this)` should be `this.myDebouncer` edit: you only need to bind in one place, you can bind in the constructor as you are doing or you can use an arrow function in the render to bind. Only need to use it. information for that here https://reactjs.org/docs/faq-functions.html#bind-in-constructor-es2015 – Andrew Nov 30 '18 at 19:01

0 Answers0