-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
43 lines (38 loc) · 1.02 KB
/
App.js
File metadata and controls
43 lines (38 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { useState, useEffect } from 'react';
import './App.css'; // You can create your custom CSS or use styled-components here
import Navbar from './Navbar';
import UserCard from './UserCard';
function App() {
const [users, setUsers] = useState([]);
const [loading, setLoading] = useState(false);
const getUsers = async () => {
setLoading(true);
try {
const response = await fetch('https://reqres.in/api/users?page=1');
const data = await response.json();
setUsers(data.data);
} catch (error) {
console.error('Error fetching users:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
getUsers();
}, []);
return (
<div className="App">
<Navbar getUsers={getUsers} />
{loading ? (
<div className="loader">Loading...</div>
) : (
<div className="user-card-grid">
{users.map(user => (
<UserCard key={user.id} user={user} />
))}
</div>
)}
</div>
);
}
export default App;