| Start |
|---|
| Using the id of an element Here we are having a list of todo items that is passed to the props of our component. Each todo item has a text and id property. Imagine that the id property comes from a backend datastore and is a unique numeric value: We set the key attribute of each iterated list element to |
| Using the array index If you don't have unique database ids at hand, you could also use the numeric index of your array like this: RemarksUsing the array index as a key is generally not recommended when the array is going to change over time. From the React Docs: As a last resort, you can pass item's index in the array as a key. This can work well if the items are never reordered, but reorders will be slow. A good example about this: https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318 (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference