@@ -6,6 +6,7 @@ import type { PostSummary } from '@apis/post/dto';
66import { handleError } from '@apis/util/handleError' ;
77import type { ModalProps } from '@components/Modal/dto' ;
88import Modal from '@components/Modal' ;
9+ import debounce from 'lodash/debounce' ;
910
1011const OOTD : React . FC = ( ) => {
1112 const [ feeds , setFeeds ] = useState < PostSummary [ ] > ( [ ] ) ;
@@ -48,25 +49,29 @@ const OOTD: React.FC = () => {
4849 } ;
4950
5051 useEffect ( ( ) => {
51- // Intersection Observer 설정
52+ if ( reachedEnd && observerRef . current && loadMoreRef . current ) {
53+ observerRef . current . unobserve ( loadMoreRef . current ) ;
54+ return ; // 더 이상 옵저버 실행 안 함
55+ }
56+
5257 observerRef . current = new IntersectionObserver (
53- ( entries ) => {
58+ debounce ( ( entries ) => {
5459 const target = entries [ 0 ] ;
55- if ( target . isIntersecting && ! isFetching ) {
60+ console . log ( 'Intersection Observer:' , target . isIntersecting ) ;
61+ if ( target . isIntersecting && ! isFetching && ! reachedEnd ) {
5662 getPostList ( ) ;
5763 }
58- } ,
64+ } , 300 ) , // 디바운스 적용
5965 {
60- root : null , // viewport
61- rootMargin : '0px' ,
62- threshold : 1. 0, // 요소가 100% 보여질 때 트리거
66+ root : null ,
67+ rootMargin : '100px' , // 미리 데이터 로드
68+ threshold : 0 , // 요소가 조금이라도 보이면 트리거
6369 } ,
6470 ) ;
6571
6672 if ( loadMoreRef . current ) {
6773 observerRef . current . observe ( loadMoreRef . current ) ;
6874 }
69-
7075 return ( ) => {
7176 if ( observerRef . current && loadMoreRef . current ) {
7277 observerRef . current . unobserve ( loadMoreRef . current ) ;
0 commit comments