Redux Injectors

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.

You can find the main repo for the library here and read the docs here.

Usage

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,
  });
  // ...
}

Note: Importing redux-injectors from utils/redux-injectors will add extra type-safety.

Last updated