MCPcopy Create free account
hub / github.com/PacktPublishing/Full-Stack-FastAPI-React-and-MongoDB / App

Function App

chapter4/users/src/App.js:4–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import {useState, useEffect} from 'react'
3
4function App() {
5
6 let [users, setUsers] = useState([])
7 let [page, setPage] = useState(1)
8
9 useEffect(()=>{
10 fetch(`https://reqres.in/api/users?page=${page}`)
11 .then(response=>response.json())
12 .then(json=>setUsers(json['data']))
13 },[page])
14
15
16 return (
17 <div className="App max-w-3xl mx-auto h-full">
18 <Header/>
19 <button className="border border-gray-500 rounded-md p-2 m-5" onClick={()=>{page===1?setPage(2):setPage(1)}}>Toggle users</button>
20 <ul>
21 {users&&users.map(el=>{
22 return (
23 <li key={el.id}>{el.email}</li>
24 )
25 })}
26 </ul>
27 </div>
28 );
29}
30export default App;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected