Browse Source

Merge pull request #340 from mateoholman/lists-and-keys-link

Added link explaining danger of using index as key
main
Brian Vaughn 7 years ago
committed by GitHub
parent
commit
a53a1afb72
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      content/docs/lists-and-keys.md

4
content/docs/lists-and-keys.md

@ -130,7 +130,9 @@ const todoItems = todos.map((todo, index) =>
);
```
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. If you choose not to assign a key to your list items then React will use indexes as keys. You may read an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) if you're interested in more information.
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an [in-depth explanation on the negative impacts of using an index as a key](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). If you choose not to assign an explicit key to list items then React will default to using indexes as keys.
Here is an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) if you're interested in learning more.
### Extracting Components with Keys

Loading…
Cancel
Save