@@ -21,15 +21,22 @@ const MemoriesPage: React.FC<MemoriesPageProps> = ({ title, memoryType, requireA
2121 const { isAuthenticated } = useAuth ( requireAuth ) ;
2222
2323 // Only fetch memories if authentication is not required or user is authenticated
24- const { memories, loading, hasMore, memoriesRef, fetchMemories, isInitialLoad } = useMemories ( {
24+ const { memories, loading, hasMore, memoriesRef, fetchMemories, isInitialLoad } = useMemories ( {
2525 memoryType,
2626 skipFetch : requireAuth && ! isAuthenticated
2727 } ) ;
2828
29+ const fetchMemoriesRef = useRef ( fetchMemories ) ;
30+
2931 const handleCreateMemory = ( ) => {
3032 navigate ( '/create-memory' ) ;
3133 } ;
3234
35+ // fetchMemories ref 업데이트
36+ useEffect ( ( ) => {
37+ fetchMemoriesRef . current = fetchMemories ;
38+ } , [ fetchMemories ] ) ;
39+
3340 // Setup intersection observer for infinite scrolling
3441 useEffect ( ( ) => {
3542 // 초기 로드 중이거나 로딩 중이면 observer 설정하지 않음
@@ -40,7 +47,7 @@ const MemoriesPage: React.FC<MemoriesPageProps> = ({ title, memoryType, requireA
4047 if ( entries [ 0 ] . isIntersecting && hasMore && ! loading ) {
4148 const currentMemories = memoriesRef . current ;
4249 const lastMemoryId = currentMemories . length > 0 ? currentMemories [ currentMemories . length - 1 ] . id : undefined ;
43- fetchMemories ( lastMemoryId ) ;
50+ fetchMemoriesRef . current ( lastMemoryId ) ;
4451 }
4552 } ,
4653 { threshold : 0.9 } // Trigger when 90% of the element is visible
@@ -57,7 +64,7 @@ const MemoriesPage: React.FC<MemoriesPageProps> = ({ title, memoryType, requireA
5764 observerRef . current . unobserve ( loadingRef . current ) ;
5865 }
5966 } ;
60- } , [ isInitialLoad , hasMore , loading , fetchMemories ] ) ;
67+ } , [ isInitialLoad , hasMore , loading ] ) ;
6168
6269 return (
6370 < Container maxW = "container.lg" centerContent flex = "1" py = { 8 } >
0 commit comments