当函数中没有参数时,可以这样设置debounce
:search = debounce ((query) => this.getTask(query), 1000);
。以及当我有多个参数时如何设置debounce
?
search = debounce ((query) => {
this.setState ({
query
}, () => this.getTask(userId, query, status)
})
答案 0 :(得分:0)
参数的数量与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>