gpt4 book ai didi

javascript - 如何使用 Redux Saga debounce 但首先获取而不是等待 n 毫秒

转载 作者:行者123 更新时间:2023-12-05 02:48:56 28 4
gpt4 key购买 nike

redux-saga 中有没有办法在例如 5 秒内只获取一次?

我知道有debounce函数:

yield debounce(5000, 'SAMPLE_ACTION', actionToFetchFirst)

但我想要的是它首先获取而不是等待 5 秒进行初始获取

最佳答案

I want is for it to fetch first rather than waiting for 5 seconds for initial fetch

您可以在 lodash.debounce options 中指定 leading=true :

lodash.debounce(func, [wait=0], [options={}])

[options.leading=false] (boolean): Specify invoking on the leading edge of the timeout.

lodash.debounce(5000, 'SAMPLE_ACTION', { leading: true });

或者只是添加一个条件,比如:

if (input.length > 1) fetchDebounced();
else fetch();

关于javascript - 如何使用 Redux Saga debounce 但首先获取而不是等待 n 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64238013/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com