how do I turn the page to get a list by using axios, drop-down refresh in react?
the following code is the ListView component of ant-mobile used to get the list of articles for demo,: https://mobile.ant.design/com.
ArticleList.js
import React, { useState, useEffect} from "react";
import { ListView,Card, WhiteSpace,Grid } from "antd-mobile";
import axios from "axios";
import "./ArticleList.less";
function ArticleList() {
const [isLoading, setIsLoading] = useState(true);
const [dataSource, setDataSource] = useState([]);
useEffect(() => {
axios.get("http://192.168.33.3/articles", {
params: {limit:10,offset:5}
}).then((response) => {
setDataSource(response.data);
}).catch(function (error) {
throw new Error(error);
}).then(function () {
setIsLoading(false);
});
});
let onEndReached = (event) => {
/* if (isLoading && !this.state.hasMore) { // hasMore: from backend data, indicates whether it is the last page, here is false
return;
}*/
setIsLoading(true);
axios.get("/articles", {
params: {limit:10,offset:5}
}).then((response) => {
setDataSource([...dataSource,...response.data]);
}).catch(function (error) {
throw new Error(error);
}).then(function () {
setIsLoading(false);
});
};
let listItem = (props) => {
return (
<div key={props.id}>
<WhiteSpace size="lg" />
<Card full>
<Card.Header title={props.user.username} thumb={props.user.avatar}/>
<Card.Body>
<div>{props.content}</div>
</Card.Body>
<Card.Footer content={props.comment_count} />
</Card>
</div>
);
};
return (
<ListView
dataSource={dataSource}
renderFooter={() => (<div style={{ padding: 30, textAlign: "center" }}>{isLoading ? "Loading..." : "Loaded"}</div>)}
renderRow={listItem}
className="am-list"
pageSize={4}
useBodyScroll
scrollRenderAheadDistance={500}
onEndReached={onEndReached}
onEndReachedThreshold={10}
/>
);
}
export default ArticleList;
question:
1, how does axios turn the page to get the article?
2. There is a commented code in the above code:
/* if (isLoading && !this.state.hasMore) { // hasMore: from backend data, indicates whether it is the last page, here is false
return;
}*/
hasMore
where should I set it?