A Redux middleware to provide easy hooks on pre/post dispatch.
$ npm i redux-hook-middleware -S
import { createStore, applyMiddleware } from 'redux'
import hookMiddleware, { registerPrehook } from 'redux-hook-middleware'
// redux setup
const initialState = { /* initial state */ }
const reducer = (state = initialState, action) => { /* reducer function logics */ return state }
const middlewares = [hookMiddleware]
const store = createStore(reducer, initialState, applyMiddleware(...middlewares))
// middleware logic
registerPrehook('HOOKING_ACTION_TYPE', (store, action) => {
console.log('prehooked!')
// do anything inside callback
// you can also dispatch other actions
store.dispatch({ type: 'SOME_ACTION_TYPE' })
})
// how does it works
store.dispatch({ type: 'HOOKING_ACTION_TYPE' }) // 'prehooked!'
Register a hook for former middleware chain and return uniq id for the hook.
Register a hook for later middleware chain and return uniq id for the hook.
Register hooks for former middleware chain and return uniq id for the hook. Pass an action type as key and a callback or an array of callbacks as value.
Register hooks for later middleware chain and return uniq id for the hook. Pass an action type as key and a callback or an array of callbacks as value.
Unregister the hook with hook id.
Unregister all the hooks registered.
$ git clone https://github.com/kamataryo/redux-hook-middleware.git
$ cd redux-hook-middleware
$ npm test