A Pen by Kajal Singh on CodePen.
Created
February 23, 2022 18:56
-
-
Save kajal1106/c4a5d33e9885877211848409107e5fb8 to your computer and use it in GitHub Desktop.
#2 React Coding - Display Array Of Users (Exercise)
This file contains 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
<div id="root"></div> |
This file contains 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
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")); |
This file contains 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
<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> |
This file contains 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
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