Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active July 4, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanCCollins/28353ffc65063d4ddb18e44096386f60 to your computer and use it in GitHub Desktop.
Save RyanCCollins/28353ffc65063d4ddb18e44096386f60 to your computer and use it in GitHub Desktop.
react keys
// 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