Skip to content

prop-types rule triggered when accessing second level properties using props[property] #298

@BerkeleyTrue

Description

@BerkeleyTrue

The following will trigger prop-types rule. As is shown, I'm accessing a second level property of a props value which shouldn't trigger prop-types error.

    handleSubmit(e) {
      e.preventDefault();
      const props = this.props;
      let valid = true;
      checkValidity.forEach((prop) => {
        // if value exist, check if it is valid
        if (props[prop].value && props[prop].type !== 'boolean') {
          valid = valid && !!props[prop].valid;
        }
      });

Error goes away if I change props to foo .

    handleSubmit(e) {
      e.preventDefault();
      const foo = this.props;
      let valid = true;
      checkValidity.forEach((prop) => {
        // if value exist, check if it is valid
        if (foo[prop].value && foo[prop].type !== 'boolean') {
          valid = valid && !!foo[prop].valid;
        }
      });

Using
[email protected]
[email protected]
[email protected]

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