Creates a store enhancer that when applied will setup the store to allow the injectors to work properly
params
Objectparams.runSaga
function A function that runs a saga. Should usually besagaMiddleware.run
params.createReducer
function A function that should create and return the root reducer. It's passed the injected reducers as the first parameter. These should be added to the root reducer usingcombineReducer
or a similar method.
import { createStore } from "redux"
import { createInjectorsEnhancer } from "redux-injectors"
function createReducer(injectedReducers = {}) {
const rootReducer = combineReducers({
...injectedReducers,
// other non-injected reducers can go here...
});
return rootReducer
}
const runSaga = sagaMiddleware.run
const store = createStore(
createReducer(),
initialState,
createInjectorsEnhancer({
createReducer,
runSaga,
})
)
Creates a "manager" component that will inject the provided reducer and saga when mounted. It only renders its children after both the reducer and saga have been injected. This is the recommended way to use redux-injectors.
options
Object
const BooksManager = createManager({ name: "BooksManager", key: "books", reducer: booksReducer, saga: booksSaga })
Returns ComponentType<{children: ReactNode}> The manager
A higher-order component that dynamically injects a reducer when the component is instantiated
params
Object
class BooksManager extends React.PureComponent {
render() {
return null;
}
}
export default injectReducer({ key: "books", reducer: booksReducer })(BooksManager)
A react hook that dynamically injects a reducer when the hook is run
params
Object
function BooksManager() {
useInjectReducer({ key: "books", reducer: booksReducer })
return null;
}
Returns boolean flag indicating whether or not the reducer has finished injecting
A higher-order component that dynamically injects a saga when the component is instantiated. There are several possible "modes" / "behaviours" that dictate how and when the saga should be injected and ejected
params
Objectparams.key
string The key to inject the saga underparams.saga
function The saga that will be injectedparams.mode
string? The injection behaviour to use. The default isSagaInjectionModes.DAEMON
which causes the saga to be started on component instantiation and never canceled or started again. @see SagaInjectionModes for the other possible modes.
class BooksManager extends React.PureComponent {
render() {
return null;
}
}
export default injectSaga({ key: "books", saga: booksSaga })(BooksManager)
A react hook that dynamically injects a saga when the hook is run
params
Object
function BooksManager() {
useInjectSaga({ key: "books", saga: booksSaga })
return null;
}
Returns boolean flag indicating whether or not the saga has finished injecting
Forces a reload of the injected reducers. i.e. Causes createReducer
to be
called again with the injected reducers. Useful for hot-reloading.
store
The redux store that has been configured withcreateInjectorsEnhancer
forceReducerReload(store);
An enum of all the possible saga injection behaviours
RESTART_ON_REMOUNT
String The saga will be started on component instantiation and cancelled withtask.cancel()
on component unmount for improved performance.DAEMON
String Causes the saga to be started on component instantiation and never canceled or started again.ONCE_TILL_UNMOUNT
String Behaves like 'RESTART_ON_REMOUNT' but never runs it again.COUNTER
String Similar to 'RESTART_ON_REMOUNT' except the saga will be mounted only once on first inject and ejected when all injectors are unmounted. This enables you to have multiple injectors with the same saga and key and only one instance of the saga will run.