Registry /
testing / redux-handler-middleware
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'
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.
fixEnsure 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.
fixUse thunk middleware for async actions, or dispatch only plain objects.
Audit
Dependencies
reduxrequiredPeer dependency for middleware functionality