Created
August 22, 2020 15:16
-
-
Save iamsaief/75238f65b202c61058e22f3f4810a3e6 to your computer and use it in GitHub Desktop.
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
import React, { useState, useEffect } from "react"; | |
function App() { | |
return ( | |
<div> | |
<Users /> | |
</div> | |
); | |
} | |
function Users() { | |
const style = { | |
textAlign: "left", | |
listStyle: "none", | |
margin: "0", | |
padding: "0", | |
}; | |
const [users, setUsers] = useState([]); | |
useEffect(() => { | |
fetch("https://jsonplaceholder.typicode.com/users") | |
.then((res) => res.json()) | |
.then((data) => setUsers(data)); | |
}, []); | |
return ( | |
<div> | |
<h3>Dynamic users: {users.length} </h3> | |
<ul style={style}> | |
{users.map((user) => ( | |
<li style={{ | |
border: "1px solid pink", | |
margin: "3px", | |
padding: "10px", | |
width: "400px", | |
}}> | |
{user.name}, <br /> | |
{user.phone},<br /> | |
{user.email} | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment