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

penx opened this issue Mar 23, 2017 · 4 comments


Copy link

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:

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:

Copy link

ljharb commented Mar 23, 2017

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

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
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.

Copy link

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

No branches or pull requests

4 participants