Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active Jul 4, 2017
Embed
What would you like to do?
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