简体   繁体   English

当一个函数有多个参数时设置去抖动lodash

[英]Setting debounce lodash when a function has several arguments

When I don't have parameters in function I set debounce in this way: search = debounce ((query) => this.getTask(query), 1000); 当我在函数中没有参数时,将以这种方式设置debouncesearch = debounce ((query) => this.getTask(query), 1000); . And how to set debounce when I have several parameters? 当我有几个参数时,如何设置debounce

  search = debounce ((query) => {
     this.setState ({
       query
     }, () => this.getTask(userId, query, status)
})

The number of parameters doesn't make a difference to debounce , it will pass everything to your function. 参数的数量不会对debounce ,它会将所有内容传递给函数。

 const search = _.debounce((param1, param2) => { console.log(param1); console.log(param2); }, 1000); search('hi', 'hello'); 
 <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM