injectReducer

Higher-Order Components for injecting Reducers asynchronously.

The Reducer with a duplicate key will be ignored.

The Reducer stays in the runtime after component is unmounted.

Arguments

  1. key (String): A string key to identify the reducer in the State.

  2. reducer (Function): A reducer function to be injected.

Returns

(Function): A Higher-Order Components function that accepts a React Component.

Example

import { compose } from 'redux'
import { connect } from 'react-redux'
import { injectEpic } from '@react-observatory/inject-epic'
import { injectReducer } from '@react-observatory/inject-reducer'
import { withRouterAction } from '@react-observatory/with-router-action'
import reducer from './reducers'
import Blog from './Blog'

function mapStateToProps({ blog }) {
  return {
    blog
  }
}

const withReducer = injectReducer('blog', reducer)

export default compose(
  withReducer,
)(Blog)

Last updated