` component makes the store available in your React components. You need this so you can use `connect()`.
### Mapping state
```js
import { connect } from 'react-redux'
```
{: .-setup}
```js
// A functional React component
function App ({ message, onMessageClick }) {
return (
onMessageClick('hello')}>
{message}
)
}
```
```js
// Maps `state` to `props`:
// These will be added as props to the component.
function mapState (state) {
return { message: state.message }
}
// Maps `dispatch` to `props`:
function mapDispatch (dispatch) {
return {
onMessageClick (message) {
dispatch({ type: 'click', message })
}
}
}
// Connect them:
export default connect(mapState, mapDispatch)(App)
```
### Shorthand
```js
export default connect(
(state) => ({
message: state.message
})
(dispatch) => ({
onMessageClick: (message) => {
dispatch({ type: 'click', message })
}
})
)(App)
```
Same as above, but shorter.
## Middleware
### Signature
```js
// noop middleware
const logger = store => dispatch => action { dispatch(action) }
```
```js
const logger = store => {
// This function runs on createStore().
// It returns a decorator for dispatch().
return dispatch => {
// Runs on createStore(), too.
// It returns a new dispatch() function
return action => {
// Runs on every dispatch()
}
}
}
```
Middlewares are simply decorators for `dispatch()` to allow you to take
different kinds of actions, and to perform different tasks when receiving
actions.
### Applying middleware
```js
const enhancer = applyMiddleware(logger, thunk, ...)
```
```js
const store = createStore(reducer, {}, enhancer)
```
{: data-line="1"}
## References
{: .-one-column}
* [Redux](https://www.npmjs.com/package/redux) _(npmjs.com)_
* [React-redux](https://www.npmjs.com/package/react-redux) _(npmjs.com)_
* [Usage with React](http://redux.js.org/docs/basics/UsageWithReact.html) _(redux.js.org)_
{: .-also-see}