React 组件的“分阶段”渲染
Others 2023-06-09 09:08:40 2023-06-09 09:08:40 1115 次浏览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;
Links: 581