【问题标题】:Setting debounce lodash when a function has several arguments当函数有多个参数时设置 debounce lodash
【发布时间】:2020-01-07 10:40:27
【问题描述】:

当我在函数中没有参数时,我以这种方式设置debouncesearch = debounce ((query) => this.getTask(query), 1000);。以及当我有多个参数时如何设置debounce

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

【问题讨论】:

    标签: javascript lodash


    【解决方案1】:

    参数的数量对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>

    【讨论】:

    • search = debounce ((query) => { this.setState ({ query }, () => this.getTask(userId, query, status) }, 1000) ?
    猜你喜欢
    • 2019-04-08
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2014-08-09
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多