Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kajal1106/c4a5d33e9885877211848409107e5fb8 to your computer and use it in GitHub Desktop.
Save kajal1106/c4a5d33e9885877211848409107e5fb8 to your computer and use it in GitHub Desktop.
#2 React Coding - Display Array Of Users (Exercise)
<div id="root"></div>
const users = [
{ name: "John Doe", id: 1 },
{ name: "Jane Doe", id: 2 },
{ name: "Billy Doe", id: 3 }
];
const usersList = users.map((user) => <li key={user.id}>{user.name}</li>);
function App() {
return (
<>
<h3>User names</h3>
<ul>{usersList}</ul>
</>
);
}
ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
h3 {
margin-left: 20px;
margin-bottom: 0;
}
ul {
margin-top: 5px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment