Last active
July 4, 2017 16:52
-
-
Save RyanCCollins/28353ffc65063d4ddb18e44096386f60 to your computer and use it in GitHub Desktop.
react keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is no good because other lists in your app could have the same index | |
{items.map((item, index) => | |
<div key={index}> | |
// ... | |
</div> | |
)} | |
// This is much better since it will most likely be unique | |
{items.map((item, index) => | |
<div key={`${item.title}-${index}`}> | |
// ... | |
</div> | |
)} | |
// This is probably the best option | |
import uuid from 'node-uuid'; | |
{items.map((item) => | |
<div key={uuid()}> | |
// ... | |
</div> | |
)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment