--- 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). ```jsx import React, { useState, useEffect } from 'react'; import { List, message, Avatar, Skeleton, Divider } from 'antd'; import InfiniteScroll from 'react-infinite-scroll-component'; const InfiniteListExample = () => { 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
)} />
); }; ReactDOM.render(, mountNode); ```