|
1 | | -import Title from '@/components/Title' |
2 | | -import { useState, use } from 'react' |
3 | | -import reactLogo from '../assets/react.svg' |
4 | | -import './App.css' |
| 1 | +import { Suspense } from 'react' |
5 | 2 |
|
6 | | -const fetchUsers = () => { |
7 | | - return fetch('https://jsonplaceholder.typicode.com/users').then((res) => res.json()) |
8 | | -} |
| 3 | +import reactLogo from '../assets/react.svg' |
9 | 4 |
|
10 | | -const fetchPosts = (userId: any) => { |
11 | | - return fetch('https://jsonplaceholder.typicode.com/posts?userId' + userId).then( |
12 | | - (res) => res.json() |
13 | | - ) |
14 | | -} |
| 5 | +import UsersPage from './users/UsersPage' |
| 6 | +import './App.css' |
15 | 7 |
|
16 | 8 | function App() { |
17 | | - const users = use(fetchUsers()) |
18 | | - |
19 | | - if (true) { |
20 | | - const posts = use(fetchPosts(users[0].id)) |
21 | | - console.log('posts', posts) |
22 | | - } |
23 | | - |
24 | | - console.log('user', users) |
25 | 9 |
|
26 | 10 | return ( |
27 | 11 | <div className="App"> |
28 | 12 | <div> |
29 | | - <a href="https://vitejs.dev" target="_blank"> |
30 | | - <img src="/vite.svg" className="logo" alt="Vite logo" /> |
31 | | - </a> |
32 | | - <a href="https://reactjs.org" target="_blank"> |
33 | | - <img src={reactLogo} className="logo react" alt="React logo" /> |
34 | | - </a> |
35 | | - </div> |
36 | | - <Title>Vite + React</Title> |
37 | | - <div className="card"> |
38 | | - {users.map((user: any) => ( |
39 | | - <p>{user.name}</p> |
40 | | - ))} |
41 | | - <p> |
42 | | - Edit <code>src/App.tsx</code> and save to test HMR |
43 | | - </p> |
| 13 | + <img src={reactLogo} className="logo react" alt="React logo" /> |
44 | 14 | </div> |
| 15 | + <Suspense fallback={<h2>Loading…</h2>}> |
| 16 | + <UsersPage /> |
| 17 | + </Suspense> |
45 | 18 | <p className="read-the-docs"> |
46 | | - Click on the Vite and React logos to learn more |
| 19 | + React 18 use() hook showcase |
47 | 20 | </p> |
48 | 21 | </div> |
49 | 22 | ) |
|
0 commit comments