import { useAsync } from 'rc-hooks'; import { Link } from 'react-router-dom'; import PageContainer from '@/components/PageContainer'; import { getReposList } from '@/services/repos'; const ListPage = () => { const { data, loading } = useAsync(() => getReposList().then((res) => res.data), { // 下面两个配置表示数据请求后进行缓存,有缓存时不再进行请求,默认缓存5分钟,可通过 cacheTime 设置缓存时间。 // 参考文档:https://doly-dev.github.io/rc-hooks/latest/index.html#/async/use-async persisted: true, cacheKey: 'repos_list' }); return (
{loading && (
列表页数据请求中...
)} {!loading && Array.isArray(data) && data.length > 0 && data.map(({ name, description }) => (

{name}

{description}

))}
); }; export default ListPage;