import React, { useState, useEffect, useRef } from 'react' import { useInView } from 'react-intersection-observer' import CircularProgress from '@mui/material/CircularProgress' interface Props { onLoadMore: () => Promise } const LazyLoad: React.FC = ({ onLoadMore }) => { const [isFetching, setIsFetching] = useState(false) 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