Skip to content

Commit

Permalink
Revert "fix(docs): remove mapDispatchToProps invalid use case" (#1365)
Browse files Browse the repository at this point in the history
This reverts commit ae6f033.
  • Loading branch information
markerikson committed Jul 26, 2019
1 parent ae6f033 commit 4cded48
Showing 1 changed file with 16 additions and 0 deletions.
Expand Up @@ -254,6 +254,22 @@ connect(
)(Counter)
```

### Manually Injecting `dispatch`

If the `mapDispatchToProps` argument is supplied, the component will no longer receive the default `dispatch`. You may bring it back by adding it manually to the return of your `mapDispatchToProps`, although most of the time you shouldn’t need to do this:

```js
import { bindActionCreators } from 'redux'
// ...

function mapDispatchToProps(dispatch) {
return {
dispatch,
...bindActionCreators({ increment, decrement, reset }, dispatch)
}
}
```

## Defining `mapDispatchToProps` As An Object

You’ve seen that the setup for dispatching Redux actions in a React component follows a very similar process: define an action creator, wrap it in another function that looks like `(…args) => dispatch(actionCreator(…args))`, and pass that wrapper function as a prop to your component.
Expand Down

0 comments on commit 4cded48

Please sign in to comment.