Enforces that mapDispatchToProps uses a shorthand method to wrap actions in dispatch calls whenever possible. (react-redux/mapDispatchToProps-prefer-shorthand)
...
connect
supports an “object shorthand” form for themapDispatchToProps
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 ofmapDispatchToProps
, unless you have a specific reason to customize the dispatching behavior.
The following patterns are considered incorrect:
const mapDispatchToProps = (dispatch) => ({
action: () => dispatch(action())
})
export default connect(null, mapDispatchToProps)(Component)
const mapDispatchToProps = (dispatch) => ({
action: () => dispatch(action()),
action1: (arg1, arg2) => dispatch(action(arg1, arg2))
})
export default connect(null, mapDispatchToProps)(Component)
The following patterns are considered correct:
export default connect(null, { action })(Component)
const mapDispatchToProps = { action }
export default connect(null, mapDispatchToProps)(Component)
const mapDispatchToProps = (dispatch) => ({
action: () => dispatch(actionHelper(true))
})
export default connect(null, mapDispatchToProps)(Component)
const mapDispatchToProps = (dispatch) => ({
action: () => dispatch(action()),
action1: (arg1, arg2) => dispatch(action(arg1 + arg2))
})
export default connect(null, mapDispatchToProps)(Component)