--- order: 6 title: zh-CN: 滚动加载 en-US: Scrolling loaded --- ## zh-CN 结合 [react-infinite-scroll-component](https://github.com/ankeetmaini/react-infinite-scroll-component) 实现滚动自动加载列表。 ## en-US The example of infinite load with [react-infinite-scroll-component](https://github.com/ankeetmaini/react-infinite-scroll-component). ```tsx import { Avatar, Divider, List, Skeleton } from 'antd'; import React, { useEffect, useState } from 'react'; import InfiniteScroll from 'react-infinite-scroll-component'; interface DataType { gender: string; name: { title: string; first: string; last: string; }; email: string; picture: { large: string; medium: string; thumbnail: string; }; nat: string; } const App: React.FC = () => { const [loading, setLoading] = useState(false); const [data, setData] = useState([]); const loadMoreData = () => { if (loading) { return; } setLoading(true); fetch('https://randomuser.me/api/?results=10&inc=name,gender,email,nat,picture&noinfo') .then(res => res.json()) .then(body => { setData([...data, ...body.results]); setLoading(false); }) .catch(() => { setLoading(false); }); }; useEffect(() => { loadMoreData(); }, []); return (
} endMessage={It is all, nothing more 🤐} scrollableTarget="scrollableDiv" > ( } title={{item.name.last}} description={item.email} />
Content
)} />
); }; export default App; ```