Unused ownProps
parameter of the React Redux mapStateToProps
function should be removed
- REACT_REDUX_UNUSED_OWN_PROPS_PARAM
- Code Quality
- Low
- react
This rule applies when the second ownProps
parameter of the React Redux mapStateToProps
function is not used.
The mapStateToProps(state, ownProps)
is specified as the first argument of connect()
call and its ownProps
parameter receives the props object of the wrapper component. If the ownProps
parameter is not present, React Redux skips calling the function at the props change.
Therefore, for performance, it is recommended to remove the ownProps
parameter if it is not used in the function body. In some cases, such modification saves not only the function execution time but also unnecessary re-renderings.
This rule also applies to the mapDispatchToProps
which takes ownProps
parameter in a similar way.
Noncompliant Code Example
View with compliant examples side by sideimport React from 'react';
import { connect } from 'react-redux';
function ShowCount(props) {
return <div>count: {props.count}</div>;
}
const mapStateToProps = (state, ownProps) => { // REACT_REDUX_UNUSED_OWN_PROPS_PARAM alarm
return { count: state.count };
}
export default connect(mapStateToProps)(ShowCount);
Compliant Code Example
View with noncompliant examples side by sideimport React from 'react';
import { connect } from 'react-redux';
function ShowCount(props) {
return <div>count: {props.count}</div>;
}
const mapStateToProps = (state) => {
return { count: state.count };
}
export default connect(mapStateToProps)(ShowCount);
Version
This rule was introduced in DeepScan 1.26.0.