React Observatory
  • Introduction
  • Motivation
  • Dynamic Injection
    • Reducers
    • Epics
  • API Reference
    • applyAsyncEpics
    • applyAsyncReducers
    • composeReducerCreator
    • createRootEpic
    • injectEpic
    • injectReducer
    • withAction
    • withRouterAction
Powered by GitBook
On this page
  • Arguments
  • Returns
  • Example
  1. API Reference

injectReducer

PreviousinjectEpicNextwithAction

Last updated 6 years ago

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

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

Returns

(Function): A 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)
Higher-Order Components
State.
reducer
Higher-Order Components