Skip to content

Commit 4cded48

Browse files
authored
Revert "fix(docs): remove mapDispatchToProps invalid use case" (#1365)
This reverts commit ae6f033.
1 parent ae6f033 commit 4cded48

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/using-react-redux/connect-dispatching-actions-with-mapDispatchToProps.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ connect(
254254
)(Counter)
255255
```
256256

257+
### Manually Injecting `dispatch`
258+
259+
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:
260+
261+
```js
262+
import { bindActionCreators } from 'redux'
263+
// ...
264+
265+
function mapDispatchToProps(dispatch) {
266+
return {
267+
dispatch,
268+
...bindActionCreators({ increment, decrement, reset }, dispatch)
269+
}
270+
}
271+
```
272+
257273
## Defining `mapDispatchToProps` As An Object
258274

259275
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.

0 commit comments

Comments
 (0)