Registry / web-framework / redux-reducers-injector

redux-reducers-injector

JSON →
library0.3.5jsnpmunverified

Library to dynamically inject reducers into a Redux store at runtime, supporting Hot Module Replacement (HMR) and Server-Side Rendering (SSR). Version 0.3.5 is the latest stable release. It wraps Redux's createStore to accept an uncombined reducer tree and allows adding reducers via injectReducer at any path. Key differentiators include support for nested reducer injection without combineReducers, forced reinjection, bulk injection, and explicit reloadReducer for HMR. Maintained by GuillaumeCisco and based on the work of redux-injector. The package has a small footprint but lacks TypeScript types and relies on lodash.set.

npm install redux-reducers-injector
INSTALL
IMPORT
SIG · REDUX-REDUCERS-INJ
R
redux-reducers-injector
web-frameworkjavascriptv0.3.5
harness data pending
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.

createInjectStore
import { createInjectStore } from 'redux-reducers-injector'
import createInjectStore from 'redux-reducers-injector'
It is a named export, not default.
injectReducer
import { injectReducer } from 'redux-reducers-injector'
const injectReducer = require('redux-reducers-injector').injectReducer
CommonJS require is acceptable but ESM is preferred. Ensure you are not using default import.
injectReducerBulk
import { injectReducerBulk } from 'redux-reducers-injector'
import { injectReducerBulk } from 'redux-reducers-injector' (typo: injectReducerBulk vs injectReducerBulk)
Named export; spelling is 'injectReducerBulk' (with capital B).
reloadReducer
import { reloadReducer } from 'redux-reducers-injector'
import { reloadReducer } from 'redux-reducers-injector' (confusion with injectReducer)
Used for HMR; forces reinjection similarly to injectReducer with force=true.

Demonstrates how to create a Redux store with redux-reducers-injector using an uncombined reducer object and inject a new reducer dynamically.

import { createStore, combineReducers } from 'redux'; import { createInjectStore, injectReducer } from 'redux-reducers-injector'; // Define reducers as a nested object (DO NOT combine) const reducersObject = { router: (state = {}, action) => state, data: { user: (state = {}, action) => state, auth: { loggedIn: (state = false, action) => state, loggedOut: (state = false, action) => state }, info: (state = {}, action) => state } }; // Create store with inject capability const store = createInjectStore(reducersObject, {}); // Later, inject a new reducer at 'data.form' const formReducer = (state = {}, action) => state; injectReducer('data.form', formReducer); // Access state as usual console.log(store.getState()); // { router: {}, data: { user: {}, auth: { loggedIn: false, loggedOut: false }, info: {}, form: {} } }
Debug
Known issues
gotchaDo NOT combine reducers with combineReducers before passing to createInjectStore. If you do, you cannot inject into any previously combined reducers.
fix
Pass an object tree of reducer functions (without combineReducers) to createInjectStore.
affects: >=0.0.0
gotchainjectReducer uses lodash.set for path resolution. Paths with dots are interpreted as nested keys. Ensure your path does not accidentally create unexpected nesting.
fix
Use string paths like 'data.form' to indicate nesting. For literal dots in keys, escape or avoid dot notation.
affects: >=0.0.0
gotchaIf you use SSR, the store reference is stored in the module's scope (singleton). Concurrent requests may share the same store reference, causing race conditions.
fix
In v0.3.0+, use the optional store parameter in injectReducer to specify a context store. For older versions, avoid SSR or implement per-request store management manually.
affects: <0.3.0
deprecatedThe package does not ship TypeScript definitions. Users must create custom .d.ts or use @types/redux-reducers-injector (if available).
fix
Add declare module 'redux-reducers-injector' { ... } or use a type assertion.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: (0 , _redux.combineReducers) is not a function
When passing a combined reducer (result of combineReducers) to createInjectStore, it tries to combine it again causing an error.
fix
Pass an object of reducer functions without combining them first.
Cannot read property 'replaceReducer' of undefined
injectReducer called before the store is created or store reference not properly set.
fix
Ensure createInjectStore is called and the store is fully initialized before calling injectReducer. For SSR, pass the store as the context parameter.
Uncaught Error: Store does not have an inject store enhancer. Did you use createInjectStore?
injectReducer called on a store that was not created with createInjectStore (e.g., created with plain createStore).
fix
Use createInjectStore (from this package) to create the store, not createStore from redux.
Upgrade
Version history
0.3.5latest on npm
Audit
Dependencies
reduxrequiredPeer dependency; needed to create and interact with the Redux store.
lodash.setrequiredRuntime dependency for setting reducer paths using dot notation.
Agent activity
4 hits · last 30 days
node
4
Resources
redux-reducers-injector — npm install redux-reducers-injector · libregistry