> For the complete documentation index, see [llms.txt](https://react-observatory.js.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://react-observatory.js.org/api-reference/injectreducer.md). Agents can also search and read this documentation through its [MCP server](https://react-observatory.js.org/~gitbook/mcp).

# injectReducer

[Higher-Order Components](https://reactjs.org/docs/higher-order-components.html) 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.](https://redux.js.org/glossary#state)
2. `reducer` (`Function`): A [reducer](https://redux.js.org/basics/reducers) function to be injected.

## Returns

(`Function`): A [Higher-Order Components](https://reactjs.org/docs/higher-order-components.html) function that accepts a React Component.

## Example

```javascript
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)
```
