Lodash debounce with React Input

后端 未结 7 1451
刺人心
刺人心 2021-02-05 04:54

I\'m trying to add debouncing with lodash to a search function, called from an input onChange event. The code below generates a type error \'function is expected\', which I unde

7条回答
  •  太阳男子
    2021-02-05 05:39

    class MyComp extends Component {
      debounceSave;
      constructor(props) {
        super(props);
      }
      this.debounceSave = debounce(this.save.bind(this), 2000, { leading: false, trailing: true });
    }
    

    save() is the function to be called

    debounceSave() is the function you actually call (multiple times).

提交回复
热议问题