A Redux middleware that allows registering pre- and post-dispatch hooks for specific action types. Version 0.1.22, likely low or no active releases. It provides functions like registerPrehook, registerPosthook, and unregisterHook to attach callbacks that execute before or after an action is dispatched. The middleware is simple and lightweight, differentiating from saga or thunk by offering a straightforward hook mechanism without generator functions or promises. It is suitable for small to medium Redux applications needing cross-cutting concerns like logging or side effects tied to specific actions.
npm install redux-hook-middlewareVerified import paths — ran on the pinned version, not inferred.
Setup Redux store with hookMiddleware, register a pre-hook for INCREMENT action, and see it log before state update.
If you need async side effects, use redux-thunk or redux-saga, or wrap async logic inside a thunk action.
Use registerPosthooks (with 's') for registering multiple hooks.
Use the provided store parameter; it is not the full store but a wrapped version with getState and dispatch.
Ensure hookMiddleware is included in the middleware array: applyMiddleware(hookMiddleware, ...otherMiddlewares)
Use named import: import { registerPrehook } from 'redux-hook-middleware'Store the symbol returned from registerPrehook/registerPosthook and pass it to unregisterHook.