你如何在React.js中进行去抖动?
我想辩论handleOnChange.
我试过debounce(this.handleOnChange, 200)但它不起作用.
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
}
});
Run Code Online (Sandbox Code Playgroud) 如何防止用户在React native中点击两次按钮?
即用户必须无法在可触摸的高光上快速点击两次