-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
30 lines (25 loc) · 868 Bytes
/
App.jsx
File metadata and controls
30 lines (25 loc) · 868 Bytes
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
import {useState} from 'react';
import axios from 'axios';
export default function App() {
const [text, setText] = useState();
const [users, setUsers] = useState([]);
const fetchText = async () => {
const res = await axios.get('/api');
setText(res.data);
}
const fetchUsers = async () => {
const res = await axios.get('/api/users');
setUsers(res.data.users);
}
return (
<div className="p-4">
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={fetchText}>Fetch Text</button>
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={fetchUsers}>Fetch Users</button>
<p>{text}</p>
<ul>
{users.map((user, i) => <li key={i}>{user}</li>)}
</ul>
<img src="/smugdog.jpg" alt="smugdog" />
</div>
);
}