在 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/