Created
June 29, 2020 05:38
-
-
Save velotiotech/83604a4fed019a802fc33d119b53f3d3 to your computer and use it in GitHub Desktop.
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
import React from "react"; | |
import { BrowserRouter, Route } from "react-router-dom"; | |
import "./App.css"; | |
const Users = () => { | |
// state | |
const [users, setUsers] = React.useState([]); | |
// effects | |
React.useEffect(() => { | |
fetch("https://jsonplaceholder.typicode.com/users") | |
.then((res) => res.json()) | |
.then((users) => { | |
setUsers(users); | |
}) | |
.catch((err) => {}); | |
}, []); | |
// render | |
return ( | |
<div> | |
<h2>Users</h2> | |
<ul> | |
{users.map((user) => ( | |
<li key={user.id}> | |
{user.name} ({user.email}) | |
</li> | |
))} | |
</ul> | |
</div> | |
); | |
}; | |
const App = () => ( | |
<BrowserRouter> | |
<Route path="/" exact component={Users} /> | |
</BrowserRouter> | |
); | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment