작성
·
357
0
useEffect(() => {
function onScroll() {
console.log(
window.scrollY,
document.documentElement.clientHeight,
document.documentElement.scrollHeight
);
if (
window.scrollY + document.documentElement.clientHeight ===
document.documentElement.scrollHeight
)
if (hasMorePost) {
const dummypost = generateDummpyPost(10);
dispatch(loadPost({ dummypost }));
}
}
window.addEventListener("scroll", onScroll);
return () => {
window.removeEventListener("scroll", onScroll);
};
}, [hasMorePost]);
useEffect를 이런 식으로 작성하면 hasMorePost의 값이 변경되기 전까지 useEffect는 처음 단한번만 실행된후 그후에는실행되지 않아야 하는데 왜 계속 console.log가 실행되는건가요?