Perform debounce in React.js

前端 未结 30 2139
礼貌的吻别
礼貌的吻别 2020-11-22 04:11

How do you perform debounce in React.js?

I want to debounce the handleOnChange.

I tried with debounce(this.handleOnChange, 200) but it doesn\'t

30条回答
  •  情书的邮戳
    2020-11-22 04:40

    Instead of wrapping the handleOnChange in a debounce(), why not wrap the ajax call inside the callback function inside the debounce, thereby not destroying the event object. So something like this:

    handleOnChange: function (event) {
       debounce(
         $.ajax({})
      , 250);
    }
    

提交回复
热议问题