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:
If there's nothing unique about the items, then you'd simply disable the rule with an override.
@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.
You can use simple 'hack'
<span> key={String(index)} </span>
And you don't pollute your code with inline disabled.
That鈥檚 just defeating the purpose of the rule. Might as well turn it off.
Most helpful comment
You can use simple 'hack'
<span> key={String(index)} </span>And you don't pollute your code with inline disabled.