Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
himynameisdave opened this issue Dec 12, 2018 · 2 comments · Fixed by #2085
Closed

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

himynameisdave opened this issue Dec 12, 2018 · 2 comments · Fixed by #2085

Comments

@himynameisdave
Copy link
Contributor

himynameisdave commented Dec 12, 2018

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

@ljharb
Copy link
Member

ljharb commented Dec 12, 2018

Sure, this seems like a reasonable addition.

@himynameisdave
Copy link
Contributor Author

@ljharb thanks! I would actually like to try fixing this (as I use this plugin a lot, so it would be cool to contribute to it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants