-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
인피니티 스크롤 파트에 질문 - useRef
20.06.25 04:14 작성 조회수 104
0
인피니티 스크롤 파트에 질문이 있습니다.
Nodebird 메인 게시글에서
아래 useRef의 countRef에 마지막 게시글 id를 넣으면서 처음 부터 끝까지 스크롤링을 하였을 때는 문제가 없는데요~
그 상태에서 다시 상단 메뉴의 Nodebird 버튼 클릭 후 게시글을 들어 가면
이미 countRef에 게시글 id가 있어 스크롤을 아래로 해도 처음 10개 이외에는 불러오지 못해요~
const countRef = useRef([]);
const onScroll = useCallback(() => {
if (window.scrollY + document.documentElement.clientHeight > document.documentElement.scrollHeight - 300) {
if (hasMorePost) {
const lastId = mainPosts[mainPosts.length - 1].id;
if (!countRef.current.includes(lastId)) {
dispatch({
type: LOAD_MAIN_POSTS_REQUEST,
lastId,
});
countRef.current.push(lastId);
}
}
}
}, [hasMorePost, mainPosts.length]);
|
|
} | |
}, [hasMorePost, mainPosts.length]); |
답변을 작성해보세요.
1
조현영
지식공유자2020.06.25
useEffect(() => {
countRef.current = [];
}, []);
으로 첫 렌더링 시 카운트를 초기화해줘도 될 것 같습니다.
0
답변 2