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

标签 javascript reactjs redux react-redux redux-saga

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/

相关文章:

javascript - react : how to prevent api calls in ComponentDidMount and in ComponentDidUpdate override each other

node.js - 将 React 应用程序部署到 Google App Engine 时出现 502 服务器错误

javascript - React/Redux 连接不会在商店更改时触发 mapStateToProps

javascript - 我应该使用nginx重写Nuxt.js吗

javascript - 无法更改 .html()

javascript - 将字符串添加到javascript文件

javascript - Redux 中间件异步函数

javascript - 我应该为大型企业应用程序使用 Material-UI 吗?

css - 在多列的material-ui表格上添加水平滚动的方法是什么?

javascript - 我是否通过替换对象中的整个数组来改变我的 reducer 状态?