
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
redux-dynamic-reducer
Advanced tools
Create Redux stores that can have additional reducers dynamically attached at runtime
This is a library to create Redux stores that can have additional reducers dynamically attached at runtime.
It is based on an example proposed by Dan Abramov in a StackOverflow answer.
Redux only supports a single root reducer for the store. When designing the store structure, combineReducers
can be used to combine multiple reducers into a single reducer for the store. However, you cannot add more reducers to the combination after the store has been created.
That's where this library fits in. It allows you to provide a single root reducer but also provide additional reducers to be merged into the root reducer after the store is created.
It also provides a useful utilities to package a component with a related reducer and attach it when the component is mounted.
The createStore
function can be used to create store that can have reducer dynamically attached. It is a drop-in replacement for the built-in Redux version:
import { combineReducers } from 'redux'
import { createStore } from 'redux-dynamic-reducer'
...
const reducer = combineReducers({ staticReducer1, staticReducer2 })
const store = createStore(reducer)
The createStore
function also supports all of the optional parameters that the built-in Redux createStore
function does:
const store = createStore(reducer, { initial: 'state' })
const store = createStore(reducer, applyMiddleware(middleware))
const store = createStore(reducer, { initial: 'state' }, applyMiddleware(middleware))
The store now has a new function on it caller attachReducers
:
store.attachReducers({ dynamicReducer })
Multiple reducers can be attached as well:
store.attachReducers({ dynamicReducer1, dynamicReducer2 })
Reducers can also be added to nested locations in the store:
store.attachReducers({
some: {
path: {
to: {
dynamicReducer
}
}
}
} )
store.attachReducers({ 'some.path.to': { dynamicReducer } } } })
store.attachReducers({ 'some/path/to': { dynamicReducer } } } })
Examples can be found here.
FAQs
Create Redux stores that can have additional reducers dynamically attached at runtime
The npm package redux-dynamic-reducer receives a total of 157 weekly downloads. As such, redux-dynamic-reducer popularity was classified as not popular.
We found that redux-dynamic-reducer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.