簡體   English   中英

當一個函數有多個參數時設置去抖動lodash

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

當我在函數中沒有參數時,將以這種方式設置debouncesearch = debounce ((query) => this.getTask(query), 1000); 當我有幾個參數時,如何設置debounce

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

參數的數量不會對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