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] Case is described in the doc is not accurate. #2909

Closed
SyMind opened this issue Jan 28, 2021 · 1 comment
Closed

Comments

@SyMind
Copy link
Contributor

SyMind commented Jan 28, 2021

In cases where the array is sorted or an element is added to the beginning of the array, the index will be changed even though the element representing that index may be the same. This results in unnecessary renders.

In React, to prevent unnecessary renders is depend on shouldComponetUpdate or memo.

In this issue facebook/react#1342 (comment),

key is not really about performance, it's more about identity (which in turn leads to better performance). randomly assigned and changing values are not identity.

When the array is sorted or an element is added to the beginning of the array and the element has it's own state, the element will render unexpectedly. I think that's the point.

@ljharb
Copy link
Member

ljharb commented Jan 30, 2021

Rendering unexpectedly is an unnecessary render. The docs seem correct to me.

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

No branches or pull requests

2 participants