Führen Sie das Entprellen in React.js durch

Wie führt man ein Debounce in React.js durch?

Ich möchte das handleOnChange entprellen.

Ich habe es mit versuchtdebounce(this.handleOnChange, 200) aber es geht nicht.

function debounce(fn, delay) {
  var timer = null;
  return function () {
    var context = this, args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
}
var SearchBox = React.createClass({

    render:function () {
    return (
    <input  type="search" name="p"
       onChange={this.handleOnChange}/>
    );
    },
    handleOnChange: function (event) {
       //make ajax call
    }
});

Antworten auf die Frage(20)

Ihre Antwort auf die Frage