-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 댓글 작성 시 업데이트가 바로 되지 않는 문제 수정 (#128)
* fix: 댓글 작성 시 업데이트가 바로 되지 않는 문제 수정 - 화면에 intersection-ref가 보이지 않으면 invalidate를 해도 업데이트가 되지 않음 (이유는 아직 모름) - 따라서 margin을 400px(휴리스틱)줘서 ref가 보이도록 수정 * fix: 댓글 작성 invalidate와 useInfiniteFetch의 충돌문제 해결
- Loading branch information
Showing
3 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { MutableRefObject, useEffect } from 'react'; | ||
import { useIntersection } from 'react-use'; | ||
|
||
const useCommentInfiniteFetch = (intersectionRef: MutableRefObject<null>, fetchCallback: () => void) => { | ||
const useCommentInfiniteFetch = ( | ||
intersectionRef: MutableRefObject<HTMLDivElement | null>, | ||
fetchCallback: () => void, | ||
feedId: string, | ||
) => { | ||
const queryClient = useQueryClient(); | ||
const intersection = useIntersection(intersectionRef, { | ||
root: null, | ||
rootMargin: `0px`, | ||
rootMargin: '0px', | ||
threshold: 1, | ||
}); | ||
|
||
useEffect(() => { | ||
if (intersection?.isIntersecting) { | ||
const commentState = queryClient.getQueryState(['comments', feedId]); | ||
|
||
if (intersection?.isIntersecting && commentState?.fetchStatus !== 'fetching') { | ||
fetchCallback(); | ||
} | ||
}, [intersection, fetchCallback]); | ||
}, [intersection, queryClient, feedId, fetchCallback]); | ||
}; | ||
|
||
export default useCommentInfiniteFetch; |