Movatterモバイル変換


[0]ホーム

URL:


UnusedownProps parameter of the React ReduxmapStateToProps function should be removed

  • REACT_REDUX_UNUSED_OWN_PROPS_PARAM
  • Code Quality
  • Low
  • react

This rule applies when the secondownProps parameter of the React ReduxmapStateToProps function is not used.

ThemapStateToProps(state, ownProps) is specified as the first argument ofconnect() call and itsownProps parameter receives the props object of the wrapper component. If theownProps parameter is not present, React Redux skips calling the function at the props change.

Therefore, for performance, it is recommended to remove theownProps 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 themapDispatchToProps which takesownProps parameter in a similar way.

Noncompliant Code ExampleCompliant Code Example
1import React from 'react';1import React from 'react';
2import { connect } from 'react-redux';2import { connect } from 'react-redux';
33
4function ShowCount(props) {4function ShowCount(props) {
5 return <div>count: {props.count}</div>;5 return <div>count: {props.count}</div>;
6}6}
7const mapStateToProps = (state, ownProps) => { // REACT_REDUX_UNUSED_OWN_PROPS_PARAM alarm7const mapStateToProps = (state) => {
8 return { count: state.count };8 return { count: state.count };
9}9}
10export default connect(mapStateToProps)(ShowCount);10export default connect(mapStateToProps)(ShowCount);

Noncompliant Code Example

View with compliant examples side by side
import 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 side
import 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.

See

Was this documentation helpful?

Last updated on April 29, 2025

[8]ページ先頭

©2009-2025 Movatter.jp