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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://react-observatory.js.org/api-reference/injectreducer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
