Skip to content

Commit

Permalink
Merge pull request #97 from Funssion-SWM/develop
Browse files Browse the repository at this point in the history
Fix: useInfinityScroll 수정
  • Loading branch information
dongree authored Jan 3, 2024
2 parents 67a5b71 + b9e7288 commit 22fe8c2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/hooks/useInfinityScroll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { Dispatch, SetStateAction, useState } from 'react';
import useObserver from '@/hooks/useObserver';

export const useInfinityScroll = <T>(
Expand All @@ -24,20 +24,19 @@ export const useInfinityScroll = <T>(
else {
setData([...data, ...item]);
}
})
.then(() => {
setIsLoading(false);
setPageNum((pre) => pre + 1);
})
.catch(() => {
setIsLoading(false);
});
};

useEffect(() => {
fetchData();
}, [pageNum]);

const onIntersect: IntersectionObserverCallback = ([entry]) => {
if (isEnd || isLoading) return;
entry.isIntersecting && setPageNum(pageNum + 1);
if (entry.isIntersecting) fetchData();
};

const { setTarget } = useObserver({ onIntersect });
Expand Down

0 comments on commit 22fe8c2

Please sign in to comment.