Created
May 1, 2019 18:59
-
-
Save jlittlejohn/1cc7c826b7ab78beaefeddb505a877e7 to your computer and use it in GitHub Desktop.
REACT: Render an Array of Objects in Stateless Functional Component
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
var users = [ | |
{ id: 1, name: "Chris" }, | |
{ id: 2, name: "Jeff" }, | |
{ id: 3, name: "Julie" }, | |
{ id: 4, name: "Jessica" } | |
]; | |
function UserList(props) { | |
var users = props.users; | |
var usersListItems = users.map(function(user) { | |
return <div key={user.id}>{user.name}</div>; | |
}); | |
return <div>{usersListItems}</div>; | |
} | |
// or | |
// function UserList(props) { | |
// var users = props.users; | |
// return ( | |
// <div> | |
// {users.map(function(user) { | |
// return <div key={user.id}>{user.name}</div>; | |
// })} | |
// </div> | |
// ); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment