Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active February 10, 2017 12:43
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 kenmori/48ff70932fa7d650a7cd0132873f749c to your computer and use it in GitHub Desktop.
Save kenmori/48ff70932fa7d650a7cd0132873f749c to your computer and use it in GitHub Desktop.
keyを持つコードとkeyを持たないコード【React】これ。Warning: flattenChildren(...): Encountered two children with the same key, `keyName`. Child keys must be unique; when two children share a key, only the first child will be used.
////////no key////////keyを持たないで返しているコード///
const users = this.state.users.map(function (user){
return <User id={user.id} name={user.name} />;
});
////////add key//////keyを設定して返しているコード///
const users = this.state.users.map(function (user){
return <User id={user.id} key={user.id} name={user.name} />;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment