{"id":18725,"library":"redux-hook-middleware","title":"redux-hook-middleware","description":"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.","status":"active","version":"0.1.22","language":"javascript","source_language":"en","source_url":"https://github.com/kamataryo/redux-hook-middleware","tags":["javascript","redux","middleware","dispatch","hook"],"install":[{"cmd":"npm install redux-hook-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add redux-hook-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-hook-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency to provide middleware and store integration.","package":"redux","optional":false}],"imports":[{"note":"Library is UMD but supports both ESM and CommonJS; named export.","wrong":"const { registerPrehook } = require('redux-hook-middleware')","symbol":"registerPrehook","correct":"import { registerPrehook } from 'redux-hook-middleware'"},{"note":"Not a default export; must use named import.","wrong":"import registerPosthook from 'redux-hook-middleware'","symbol":"registerPosthook","correct":"import { registerPosthook } from 'redux-hook-middleware'"},{"note":"Named export; no common mistake but note it removes all hooks.","wrong":null,"symbol":"clearHooks","correct":"import { clearHooks } from 'redux-hook-middleware'"}],"quickstart":{"code":"import { createStore, applyMiddleware } from 'redux';\nimport hookMiddleware, { registerPrehook } from 'redux-hook-middleware';\n\nconst initialState = { count: 0 };\nconst reducer = (state = initialState, action) => {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { count: state.count + 1 };\n    default:\n      return state;\n  }\n};\n\nconst store = createStore(reducer, applyMiddleware(hookMiddleware));\n\nregisterPrehook('INCREMENT', (store, action) => {\n  console.log('About to increment, current count:', store.getState().count);\n});\n\nstore.dispatch({ type: 'INCREMENT' }); // logs: About to increment, current count: 0","lang":"javascript","description":"Setup Redux store with hookMiddleware, register a pre-hook for INCREMENT action, and see it log before state update."},"warnings":[{"fix":"If you need async side effects, use redux-thunk or redux-saga, or wrap async logic inside a thunk action.","message":"Hooks are called synchronously; cannot use async callbacks for side effects without additional handling.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use registerPosthooks (with 's') for registering multiple hooks.","message":"registerPrehook and registerPosthooks have a typo ('onject' in the README) which may cause confusion.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use the provided store parameter; it is not the full store but a wrapped version with getState and dispatch.","message":"Hook callbacks receive a limited store API (getState, dispatch) but not the full Redux store.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure hookMiddleware is included in the middleware array: applyMiddleware(hookMiddleware, ...otherMiddlewares)","cause":"The library expects hookMiddleware to be applied, but it was not added to applyMiddleware.","error":"Uncaught Error: Could not find hookMiddleware in the middleware chain"},{"fix":"Use named import: import { registerPrehook } from 'redux-hook-middleware'","cause":"Incorrect import; trying to use default import instead of named import.","error":"registerPrehook is not a function"},{"fix":"Store the symbol returned from registerPrehook/registerPosthook and pass it to unregisterHook.","cause":"unregisterHook expects a Symbol returned from registerHook, but a string or number was passed.","error":"TypeError: hookId is not a symbol"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}