### Table of Contents - [Setup][1] - [createInjectorsEnhancer][2] - [Parameters][3] - [Examples][4] - [Managers][5] - [createManager][6] - [Parameters][7] - [Examples][8] - [Injectors][9] - [injectReducer][10] - [Parameters][11] - [Examples][12] - [useInjectReducer][13] - [Parameters][14] - [Examples][15] - [injectSaga][16] - [Parameters][17] - [Examples][18] - [useInjectSaga][19] - [Parameters][20] - [Examples][21] - [Misc][22] - [forceReducerReload][23] - [Parameters][24] - [Examples][25] - [SagaInjectionModes][26] - [Properties][27] ## Setup ### createInjectorsEnhancer Creates a store enhancer that when applied will setup the store to allow the injectors to work properly #### Parameters - `params` **[Object][28]** - `params.runSaga` **[function][29]** A function that runs a saga. Should usually be `sagaMiddleware.run` - `params.createReducer` **[function][29]** 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 using `combineReducer` or a similar method. #### Examples ```javascript 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, }) ) ``` ## Managers ### createManager 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. #### Parameters - `options` **[Object][28]** - `options.name` **[string][30]** The name to give the manager that shows up in the react devtools - `options.key` **[string][30]** The key to inject the reducer under - `options.reducer` **[function][29]?** The reducer that will be injected - `options.saga` **[function][29]?** The saga that will be injected #### Examples ```javascript const BooksManager = createManager({ name: "BooksManager", key: "books", reducer: booksReducer, saga: booksSaga }) ``` Returns **ComponentType<{children: ReactNode}>** The manager ## Injectors ### injectReducer A higher-order component that dynamically injects a reducer when the component is instantiated #### Parameters - `params` **[Object][28]** - `params.key` **[string][30]** The key to inject the reducer under - `params.reducer` **[function][29]** The reducer that will be injected #### Examples ```javascript class BooksManager extends React.PureComponent { render() { return null; } } export default injectReducer({ key: "books", reducer: booksReducer })(BooksManager) ``` ### useInjectReducer A react hook that dynamically injects a reducer when the hook is run #### Parameters - `params` **[Object][28]** - `params.key` **[string][30]** The key to inject the reducer under - `params.reducer` **[function][29]** The reducer that will be injected #### Examples ```javascript function BooksManager() { useInjectReducer({ key: "books", reducer: booksReducer }) return null; } ``` Returns **[boolean][31]** flag indicating whether or not the reducer has finished injecting ### injectSaga 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 #### Parameters - `params` **[Object][28]** - `params.key` **[string][30]** The key to inject the saga under - `params.saga` **[function][29]** The saga that will be injected - `params.mode` **[string][30]?** The injection behaviour to use. The default is `SagaInjectionModes.DAEMON` which causes the saga to be started on component instantiation and never canceled or started again. @see [SagaInjectionModes][26] for the other possible modes. #### Examples ```javascript class BooksManager extends React.PureComponent { render() { return null; } } export default injectSaga({ key: "books", saga: booksSaga })(BooksManager) ``` ### useInjectSaga A react hook that dynamically injects a saga when the hook is run #### Parameters - `params` **[Object][28]** - `params.key` **[string][30]** The key to inject the saga under - `params.saga` **[function][29]** The saga that will be injected #### Examples ```javascript function BooksManager() { useInjectSaga({ key: "books", saga: booksSaga }) return null; } ``` Returns **[boolean][31]** flag indicating whether or not the saga has finished injecting ## Misc ### forceReducerReload Forces a reload of the injected reducers. i.e. Causes `createReducer` to be called again with the injected reducers. Useful for hot-reloading. #### Parameters - `store` The redux store that has been configured with `createInjectorsEnhancer` #### Examples ```javascript forceReducerReload(store); ``` ### SagaInjectionModes An enum of all the possible saga injection behaviours #### Properties - `RESTART_ON_REMOUNT` **[String][30]** The saga will be started on component instantiation and cancelled with `task.cancel()` on component unmount for improved performance. - `DAEMON` **[String][30]** Causes the saga to be started on component instantiation and never canceled or started again. - `ONCE_TILL_UNMOUNT` **[String][30]** Behaves like 'RESTART_ON_REMOUNT' but never runs it again. - `COUNTER` **[String][30]** 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. [1]: #setup [2]: #createinjectorsenhancer [3]: #parameters [4]: #examples [5]: #managers [6]: #createmanager [7]: #parameters-1 [8]: #examples-1 [9]: #injectors [10]: #injectreducer [11]: #parameters-2 [12]: #examples-2 [13]: #useinjectreducer [14]: #parameters-3 [15]: #examples-3 [16]: #injectsaga [17]: #parameters-4 [18]: #examples-4 [19]: #useinjectsaga [20]: #parameters-5 [21]: #examples-5 [22]: #misc [23]: #forcereducerreload [24]: #parameters-6 [25]: #examples-6 [26]: #sagainjectionmodes [27]: #properties [28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean