Executar debounce no React.js
Como você executa debounce no React.js?
Eu quero renunciar ao handleOnChange.
Eu tentei comdebounce(this.handleOnChange, 200)
mas não funciona.
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
}
});