diff --git a/src/hooks/useInfinityScroll.ts b/src/hooks/useInfinityScroll.ts index 1f57918..9b13cb8 100644 --- a/src/hooks/useInfinityScroll.ts +++ b/src/hooks/useInfinityScroll.ts @@ -1,4 +1,4 @@ -import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'; +import { Dispatch, SetStateAction, useEffect, useState } from 'react'; import useObserver from '@/hooks/useObserver'; export const useInfinityScroll = ( @@ -13,7 +13,6 @@ export const useInfinityScroll = ( const [pageNum, setPageNum] = useState(1); const [isEnd, setIsEnd] = useState(false); const [isLoading, setIsLoading] = useState(false); - const isInitialMount = useRef(true); const fetchData = () => { if (isLoading || isEnd) return; @@ -21,11 +20,11 @@ export const useInfinityScroll = ( fn(pageNum) .then((item) => { - setIsLoading(false); if (!item.length) setIsEnd(true); else { setData([...data, ...item]); } + setIsLoading(false); }) .catch(() => { setIsLoading(false); @@ -33,11 +32,7 @@ export const useInfinityScroll = ( }; useEffect(() => { - if (isInitialMount.current) { - isInitialMount.current = false; - } else { - fetchData(); - } + fetchData(); }, [pageNum]); const onIntersect: IntersectionObserverCallback = ([entry]) => {