eslint-plugin-react-redux
Advanced tools
Comparing version
# Enforces that mapDispatchToProps uses a shorthand method to wrap actions in dispatch calls whenever possible. (react-redux/mapDispatchToProps-prefer-shorthand) | ||
>[mapDispatchToProps(dispatch, [ownProps]): dispatchProps] (Object or Function): If an object is passed, each function inside it is assumed to be a Redux action creator. An object with the same function names, but with every action creator wrapped into a dispatch call so they may be invoked directly, will be merged into the component’s props. | ||
>...`connect` supports an “object shorthand” form for the `mapDispatchToProps` argument: if you pass an object full of action creators instead of a function, `connect` will automatically call bindActionCreators for you internally. We recommend always using the “object shorthand” form of `mapDispatchToProps`, unless you have a specific reason to customize the dispatching behavior. | ||
[source](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) | ||
[source](https://github.com/reduxjs/react-redux/blob/master/docs/using-react-redux/connect-dispatching-actions-with-mapDispatchToProps.md#defining-mapdispatchtoprops-as-an-object) | ||
## Rule details | ||
The following pattern is considered incorrect: | ||
The following patterns are considered incorrect: | ||
@@ -15,5 +15,3 @@ ```js | ||
}) | ||
// it should use equivalent shorthand wrapping instead: | ||
// const mapDispatchToProps = {action} | ||
export default connect(null, mapDispatchToProps)(Component) | ||
``` | ||
@@ -26,2 +24,3 @@ | ||
}) | ||
export default connect(null, mapDispatchToProps)(Component) | ||
``` | ||
@@ -33,9 +32,15 @@ | ||
```js | ||
const mapDispatchToProps = {action} | ||
export default connect(null, { action })(Component) | ||
``` | ||
```js | ||
const mapDispatchToProps = { action } | ||
export default connect(null, mapDispatchToProps)(Component) | ||
``` | ||
```js | ||
const mapDispatchToProps = (dispatch) => ({ | ||
action: () => dispatch(actionHelper(true)) | ||
}) | ||
export default connect(null, mapDispatchToProps)(Component) | ||
``` | ||
@@ -48,2 +53,3 @@ | ||
}) | ||
export default connect(null, mapDispatchToProps)(Component) | ||
``` |
{ | ||
"name": "eslint-plugin-react-redux", | ||
"version": "3.3.2", | ||
"version": "3.3.4", | ||
"description": "Enforcing best practices for react-redux", | ||
@@ -18,3 +18,4 @@ "keywords": [ | ||
"commitmsg": "npm run test && commitlint -e $GIT_PARAMS", | ||
"build": "rm -fr ./dist && babel ./src --out-dir ./dist --copy-files" | ||
"build": "rm -fr ./dist && babel ./lib --out-dir ./dist --copy-files", | ||
"prepublishOnly": "npm test && npm run build" | ||
}, | ||
@@ -21,0 +22,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
117870
32.15%64
30.61%2884
35.97%