bug: try improve loading performance

This commit is contained in:
2023-01-22 11:17:50 +00:00
parent c91325ecd6
commit e830b39edf
6 changed files with 89 additions and 87 deletions

View File

@ -1,13 +1,22 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useInView } from "react-intersection-observer";
export default function LoadMore({ onLoadMore }: { onLoadMore: () => void }) {
export default function LoadMore({ onLoadMore, shouldLoadMore }: { onLoadMore: () => void, shouldLoadMore: boolean }) {
const { ref, inView } = useInView();
const [tick, setTick] = useState<number>(0);
useEffect(() => {
if (inView === true) {
if (inView === true && shouldLoadMore === true) {
onLoadMore();
}
}, [inView]);
}, [inView, shouldLoadMore, tick]);
useEffect(() => {
let t = setInterval(() => {
setTick(x => x += 1);
}, 500);
return () => clearInterval(t);
}, []);
return <div ref={ref} className="mb10">Loading...</div>;
}