Registry / testing / redux-handler-middleware

redux-handler-middleware

JSON →
library1.0.4jsnpmunverified

Redux middleware that executes custom handlers before and after state updates, useful for navigation redirects. Version 1.0.4 is the latest stable release (no updates since 2017). Key differentiator: declarative handler definitions for specific actions, both pre- and post-update. Lightweight (no dependencies). Similar to redux-saga but simpler for basic side effects. Compatible with Redux >= 3.

npm install redux-handler-middleware
INSTALL
IMPORT
SIG · REDUX-HANDLER-MIDD
R
redux-handler-middleware
testingjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createHandlerMiddleware
✓ import createHandlerMiddleware from 'redux-handler-middleware'
✗ const createHandlerMiddleware = require('redux-handler-middleware')
Default export. CommonJS require works as well.
handlerObjects
✓ const handlers = [{ actions: ['ACTION_TYPE'], beforeHandler: fn, afterHandler: fn }]
✗ const handlers = [{ action: 'ACTION_TYPE' }]
Use 'actions' (array) or 'action' (string) but not both.
applyMiddleware
✓ import { applyMiddleware } from 'redux'
✗ import { applyMiddleware } from 'redux-handler-middleware'
applyMiddleware is part of Redux core, not this library.

Shows how to create a handler middleware that logs after an increment action.

import { createStore, applyMiddleware } from 'redux'; import createHandlerMiddleware from 'redux-handler-middleware'; const reducer = (state = { count: 0 }, action) => { switch (action.type) { case 'INCREMENT': return { count: state.count + 1 }; default: return state; } }; const handlerMiddleware = createHandlerMiddleware([ { actions: ['INCREMENT'], afterHandler: (store, action) => { console.log('Count after increment:', store.getState().count); } } ]); const store = createStore(reducer, applyMiddleware(handlerMiddleware)); store.dispatch({ type: 'INCREMENT' }); // Logs: 'Count after increment: 1'
Debug
Known issues
gotchaHandler objects must use 'actions' as an array or 'action' as a string, not both.
fix
Use either 'actions: [TYPE]' or 'action: TYPE', not both properties.
affects: >=1.0.0
gotchaAsync handlers (e.g., API calls) are not supported; handlers are synchronous.
fix
For async side effects, use redux-thunk or redux-saga.
affects: >=1.0.0
deprecatedPackage has not been updated since 2017; may not work with newer Redux versions.
fix
Consider using redux-saga or middleware chains for modern Redux.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: handler.actions is not iterable
Handler expects 'actions' as an array or 'action' as a string; providing neither causes iteration error.
fix
Ensure each handler object has either 'actions' (array) or 'action' (string) property.
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
Dispatching a function or promise; handlerMiddleware doesn't handle async actions.
fix
Use thunk middleware for async actions, or dispatch only plain objects.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
reduxrequiredPeer dependency for middleware functionality
Agent activity
8 hits · last 30 days
node
8
Resources
redux-handler-middleware — npm install redux-handler-middleware · libregistry