Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 29, 2020 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/83604a4fed019a802fc33d119b53f3d3 to your computer and use it in GitHub Desktop.
Save velotiotech/83604a4fed019a802fc33d119b53f3d3 to your computer and use it in GitHub Desktop.
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