Redux-debounced is a middleware for Redux designed to manage the dispatching of fast-paced actions. It enables developers to debounce actions by adding specific metadata to the action object, ensuring that the Redux state is updated only after a defined period of inactivity following the last dispatch of a particular action. This functionality is crucial for optimizing performance in scenarios like search input fields, where continuous user input could otherwise trigger an excessive number of API requests or state changes. The package is currently at version 0.5.0, with its last publish date in April 2018, which suggests it is in a maintenance state with no active development or regular release cadence. Its primary distinction lies in its direct integration within the Redux middleware chain, utilizing Flux Standard Actions (FSA) for configuration, offering an alternative to debouncing at the component level or within action creators.
npm install redux-debouncedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `redux-debounced` middleware with `redux-thunk` and dispatch debounced actions, including how to configure a unique key for thunks to enable proper debouncing and cancellation.
Ensure `createDebounce()` is listed before `thunkMiddleware` in `applyMiddleware`. Add a unique `key` property within `action.meta.debounce` for all debounced thunks.
Be aware of this behavior and design your action flow accordingly. If further side effects are needed after a cancellation, dispatch a separate, non-debounced action specifically for those effects.
Consider alternatives like debouncing in action creators using `lodash.debounce` or `redux-saga`'s `debounce` effect, especially when using Redux Toolkit. If using `redux-debounced`, thoroughly test compatibility with your current stack.
Ensure actions adhere to the Flux Standard Action (FSA) pattern with a `meta` object containing a `debounce` object, which itself has a `time` property (e.g., `{ type: 'MY_ACTION', meta: { debounce: { time: 300 } } }`).When setting up middleware, ensure `createDebounce()` comes before `thunkMiddleware` (e.g., `applyMiddleware(createDebounce(), thunkMiddleware)`). For thunks, always include `thunk.meta = { debounce: { time: 500, key: 'UNIQUE_THUNK_KEY' } };`.Verify that all actions intended to be debounced conform to the expected FSA `meta.debounce` structure. If non-debounced actions are accidentally being processed, ensure your action creators correctly attach the `meta` object only when needed, or defensively check for its existence in custom middleware.