Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Last active August 11, 2017 00:13
Show Gist options
  • Save treyhuffine/0287b093c482c56121e99ad96e91a075 to your computer and use it in GitHub Desktop.
Save treyhuffine/0287b093c482c56121e99ad96e91a075 to your computer and use it in GitHub Desktop.
function ListItem(props) {
// Correct! There is no need to specify the key here:
return <li>{props.value}</li>;
}
function UserList(props) {
const users = props.users;
const listItems = users.map((user) =>
// Correct! Key should be specified inside the array.
<ListItem key={user.id.toString()}
value={user.name} />
);
return (
<ul>
{listItems}
</ul>
);
}
const users = [
{id: 1, name: 'Khaleesi'} ,
{id: 2, name: 'Jon'},
{id: 3, name: 'Arya'}
];
<UserList users={users} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment