简体   繁体   中英

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); . And how to set debounce when I have several parameters?

  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.

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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