Created
November 27, 2018 14:55
-
-
Save gnzandrs/0322fcc8da69ee2d8da0294f38b0b28e to your computer and use it in GitHub Desktop.
react key atribute example for medium
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
// forma incorrecta | |
render() { | |
return ( | |
<div> | |
{( | |
this.state.usuarios.map((id, index) => { | |
return <Usuario | |
key = {index} | |
id = {id} | |
/> | |
}) | |
)} | |
</div> | |
) | |
} | |
// forma correcta | |
render() { | |
return ( | |
<div> | |
{( | |
this.state.usuarios.map((id, index) => { | |
return <Usuario | |
key = {id} // utilizamos el id unico como key | |
id = {id} | |
/> | |
}) | |
)} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment