> For the complete documentation index, see [llms.txt](https://cansahin.gitbook.io/react-boilerplate-cra-template/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cansahin.gitbook.io/react-boilerplate-cra-template/building-blocks/slice/redux-injectors.md).

# Redux Injectors

[`redux-injectors`](https://github.com/react-boilerplate/redux-injectors) is an official `react-boilerplate` companion library. We built it so that it can be used and maintained independently from `react-boilerplate`. It allows you to dynamically load reducers and sagas as needed, instead of loading them all upfront. This has some nice benefits, such as avoiding having to manage a big global list of reducers and sagas. It also facilitates more effective use of [code-splitting](https://webpack.js.org/guides/code-splitting/).

You can find the main repo for the library [here](https://github.com/react-boilerplate/redux-injectors) and read the docs [here](https://github.com/react-boilerplate/redux-injectors/blob/master/docs/api.md).

## Usage

```typescript
import {
  useInjectSaga,
  useInjectReducer,
  SagaInjectionModes,
} from 'utils/redux-injectors';
import { saga } from './saga';
import { reducer } from '.';

export function SomeComponent() {
  useInjectReducer({ key: 'SomeComponent', reducer });
  useInjectSaga({
    key: 'SomeComponent',
    saga,
    mode: SagaInjectionModes.DAEMON,
  });
  // ...
}
```

{% hint style="info" %}
**Note:** Importing `redux-injectors` from `utils/redux-injectors` will add extra type-safety.
{% endhint %}
