import React, { useState, useEffect, useRef } from 'react'; import { useInView } from 'react-intersection-observer'; import CircularProgress from '@mui/material/CircularProgress'; import { useTheme } from '@mui/material'; interface Props { onLoadMore: () => Promise; } const LazyLoad: React.FC = ({ onLoadMore }) => { const [isFetching, setIsFetching] = useState(false); const theme = useTheme(); const firstLoad = useRef(false); const [ref, inView] = useInView({ threshold: 0.7, }); useEffect(() => { if (inView) { setIsFetching(true); onLoadMore().finally(() => { setIsFetching(false); firstLoad.current = true; }); } }, [inView]); return (
); }; export default LazyLoad;