Skip to content

no-array-index-key not working in React.Children.map #2083

Closed
@himynameisdave

Description

@himynameisdave

Hi! This currently does not flag an error with no-array-index-key:

React.Children.map(this.props.children, (child, index) => {
    const className = classnames(
                        child.props.className,
                        `${this.props.transition}-finished`
                    );
    return React.cloneElement(child, { key: index, className });
});

Specifically, I would expect the key: index part to trigger the no-array-index-key warning.

(I realize that there is probably a better way to write this (ie: not using cloneElement), but I noticed this recently and saw that it didn't flag the warning.


PS: Thanks for the awesome ESLint plugin! 🎉 Can't wait for the next release!

mcbook

Metadata

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