useEffect(() => {
function onScroll() {
console.log(window.scrollY, document.documentElement.clientHeight, document.documentElement.scrollHeight);
if (window.scrollY + document.documentElement.clientHeight === document.documentElement.scrollHeight) {
if (hasMorePost) {
dispatch({
type: LOAD_POSTS_REQUEST,
});
}
}
}
window.addEventListener('scroll', onScroll);
return () => {
window.removeEventListener('scroll', onScroll);
};
}, [hasMorePost]);
강의 중간까지 일단 실행해보면서 잘 되는지 확인하고 있는데요
콘솔창 확인해보면 지금 제일 마지막 내용이 끝까지 스크롤했을 때거든요
제로초님 강의에서는 딱 정수로 나와서 window.scrollY + document.documentElement.clientHeight === document.documentElement.scrollHeight 가 성립하는데 저는 저렇게 소수점으로 나와서 제대로 작동안하는걸까요? 가끔 다시 run dev하면 작동할때도 있고 안할때도 있고.. 코드들은 다 문제없는데 뭐가 문제인지 모르겠네요
