Skip to content

prop-types false positive on internal render method with a destructure parameter #1346

Closed
@alangpierce

Description

@alangpierce

In this code, I think the _renderValue method is being treated as a stateless functional component, and the prop-types rule is complaining about the value parameter:

const MyComponent = React.createClass({
  propTypes: {
    values: React.PropTypes.arrayOf(React.PropTypes.number.isRequired).isRequired,
  },

  _renderValue({value}) {  // Error: 'value' is missing in props validation (react/prop-types)
    return <span>{value}</span>;
  },

  render() {
    return (
      <div>
        {this.props.values.map((value) => this._renderValue({value}))}
      </div>
    );
  },
});

Note that this only seems to happen when there are destructured params and only when using React.createClass, not ES2015 classes. It seems like a reasonable fix (if I'm interpreting the problem correctly) would be to say that a function isn't an SFC if it's defined using method syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions