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

react/no-array-index-key - Breaking this.props.children in to chunks and using index as a key #1123

Closed
penx opened this issue Mar 23, 2017 · 4 comments
Labels

Comments

@penx
Copy link
Contributor

penx commented Mar 23, 2017

Are there circumstances when it is ok to use array index as a key? If so, could these exceptions be added to the documentation here:

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md

I have run in to an issue where I am breaking down this.props.children in to several chunks in order to render them in a grid - but I can't see how I could use anything other than the array index as an identifier - more information here:

http://stackoverflow.com/questions/42983067/breaking-children-in-to-chunks-and-react-no-array-index-key

@ljharb
Copy link
Member

ljharb commented Mar 23, 2017

If there's nothing unique about the items, then you'd simply disable the rule with an override.

@NullDivision
Copy link

@penx If you have a static set it should be ok to use the array index as values. If you have other features (eg. filtering) then it's recommended to use a unique key to avoid index collisions since React uses keys first to check if a node should be updated.

@ljharb ljharb added the question label May 4, 2017
@ljharb ljharb closed this as completed May 4, 2017
@mewhit
Copy link

mewhit commented Feb 5, 2019

You can use simple 'hack'
<span> key={String(index)} </span>
And you don't pollute your code with inline disabled.

@ljharb
Copy link
Member

ljharb commented Feb 5, 2019

That’s just defeating the purpose of the rule. Might as well turn it off.

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

No branches or pull requests

4 participants