I use @ionic/react version 5.0.7, and IonInfiniteScroll & IonInfiniteScrollContent and it works fine.
import {
IonContent,
IonInfiniteScroll,
IonInfiniteScrollContent,
IonLabel,
IonPage,
useIonViewDidEnter,
} from "@ionic/react";
import React, { useEffect, useState } from "react";
import { RootStateOrAny, useDispatch, useSelector } from "react-redux";
import { Col, Container, Row } from "reactstrap";
import { alertActions } from "../../actions/alert";
import Header from "../../components/Shared/Header";
import GeneralSkeletonText from "../../components/skeleton_text/general_restaurant";
import axios from "../../helpers/axiosInterceptor";
const Orders: React.FC = (props: any) => {
const [orderList, setOrderList] = useState<any>([]);
const [load, setLoad] = useState(false);
const [disableInfiniteScroll, setDisableInfiniteScroll] =
useState<boolean>(false);
const [page, setPage] = useState(1);
const dispatch = useDispatch();
async function fetchData(temp) {
axios
.get("/orders?page=" + temp)
.then(async (res: any) => {
if (res && res.data && res.data.length > 0) {
setOrderList([...orderList, ...res.data]);
setDisableInfiniteScroll(res.data.length < 5);
} else {
setDisableInfiniteScroll(true);
}
})
.catch((err) => console.error(err));
}
async function searchNext($event: CustomEvent<void>) {
let temp = page + 1;
setPage(temp);
await fetchData(temp);
($event.target as HTMLIonInfiniteScrollElement).complete();
}
useIonViewDidEnter(() => {
axios
.get(`/orders`)
.then((res) => {
const data = res.data;
setOrderList(data);
setDisableInfiniteScroll(data.length < 5);
setLoad(true);
})
.catch((err) => {
dispatch(alertActions.error("There are errors, please try again!"));
dispatch(alertActions.page_loader(false));
});
});
useEffect(() => {
if (!load) {
axios
.get(`/orders`)
.then((res) => {
const data = res.data;
setOrderList(data);
setDisableInfiniteScroll(data.length < 5);
setLoad(true);
})
.catch((err) => {
console.log(err);
});
}
}, [load]);
return (
<IonPage>
<Header
name="Orders"
click={() => props.history.goBack()}
back={false}
></Header>
<IonContent fullscreen>
{load ? (
orderList.length == 0 ? (
<Container fluid={true} className="h-100 d-flex align-items-center">
<Col>
....
</Col>
</Container>
) : (
<div>
{orderList.map((data: any, key) => {
return (
<div
className="h-flex pt-20"
key={key}
style={
key == orderList.length - 1 ? { marginBottom: 20 } : {}
}
onClick={() => props.history.push(`/order/${data.id}`)}
>
<div className="col-12">
....
</div>
</div>
);
})}
<IonInfiniteScroll
threshold="100px"
disabled={disableInfiniteScroll}
onIonInfinite={(e: CustomEvent<void>) => searchNext(e)}
>
<IonInfiniteScrollContent loadingText="Loading..."></IonInfiniteScrollContent>
</IonInfiniteScroll>
</div>
)
) : (
[...Array(5)].map((e, i) => (
<Container className="mt-3 p-0" key={i}>
<GeneralSkeletonText />
</Container>
))
)}
</IonContent>
</IonPage>
);
};
export default Orders;
This is my code, maybe can help.