Skip to content

react/no-used-prop-types error thrown when a prop is only used in nextProps #1142

Closed
@mjilugu

Description

@mjilugu

When we use a prop only with nextProps to set the state in the componentWillRecieveProps(nextProps) method and not elsewhere we get react/no-used-prop-types error for the prop in the propTypes block.

Same as #801

Here is an excerpt of my code:

class MyComponent extends React.Component {

  static propTypes = {
    isLoading: React.PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
    error: React.PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
  }

  static defaultProps = {
    isLoading: true,
    error: false,
  };

  constructor(props) {
    super(props);

    this.state = {
      isLoading: true,
      error: false,
    };
  }

  componentWillReceiveProps(props) {
    if (props.error) {
      this.setState({ ...this.state, error: props.error });
    } else {
      this.setState({
        ...this.state,
        isLoading: props.isLoading,
        error: false,
      });
    }
  }

  // the rest of the code
}

Notice I have to use // eslint-disable-line react/no-unused-prop-types to avoid the warnings

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions