React 组件的“分阶段”渲染
emer 发布于 2023-6-9 17:08 1084 次阅读
https://zhuanlan.zhihu.com/p/139318295
https://github.com/awmleer/staged-components
也可用
useSWR
import { useState } from "react"; import useSWR from "swr"; import "./App.css"; const fetcher = (url) => fetch(url).then((res) => res.json()); function App() { const [count, setCount] = useState("思路"); // /api-bz/temp.php?url=www.free-api.com const { data, error, isLoading } = useSWR( "http://jsonplaceholder.typicode.com/users/5", fetcher ); if (error) return <div>error</div>; const res = useSWR("http://jsonplaceholder.typicode.com/users", fetcher); return ( <> <div>{count}</div> <div>{data?.email}</div> <div>{res?.data?.[0]?.phone}</div> </> ); } export default App;