vasanthk / react-bits

✨ React patterns, techniques, tips and tricks ✨
https://vasanthk.gitbooks.io/react-bits
Creative Commons Attribution 4.0 International
16.97k stars 1.1k forks source link

[Using Indexes as Key] Misleading information #67

Closed Nathan-Schwartz closed 7 years ago

Nathan-Schwartz commented 7 years ago

Anti-patterns' Using Indexes as key section is based on an outdated article and is no longer correct.

Keys should be stable, predictable, and unique. Unstable keys (like those produced by Math.random()) will cause many component instances and DOM nodes to be unnecessarily recreated, which can cause performance degradation and lost state in child components.

A more entertaining explanation can be found here (credit to Lin Clark).

Suggestions:

@vasanthk I'm happy to open a PR for this, if you are satisfied with the suggestions I made 👍

vasanthk commented 7 years ago

@Nathan-Schwartz Thank you for this. Happy to accept a PR :)