Skip to content

Using a prop as an object key to call a function, incorrectly reports missing in props validation #132

Closed
@Standard8

Description

Testcase:

var TestComp1 = React.createClass({
  propTypes: {
    size: React.PropTypes.string.isRequired
  },

  render: function() {
    var foo = {
      "abc": ["1", "2", "3"]
    };

    var icons = foo[this.props.size].map(function() {
      return null;
    });
    return (<div>{icons}</div>);
  }
});

Output:

  11:37  error  'size[].map' is missing in props validation  react/prop-types

 1 problem (1 error, 0 warnings)

this.props.size is being used as the key for the object, not as an object itself.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions