Skip to content

Instantly share code, notes, and snippets.

@iamsaief
Created August 22, 2020 15:16
Show Gist options
  • Save iamsaief/75238f65b202c61058e22f3f4810a3e6 to your computer and use it in GitHub Desktop.
Save iamsaief/75238f65b202c61058e22f3f4810a3e6 to your computer and use it in GitHub Desktop.
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