강의

멘토링

커뮤니티

Inflearn Community Q&A

nicealice991462's profile image
nicealice991462

asked

[Renewal] Creating NodeBird SNS with React

Applying infinite scrolling

onScroll 함수에서

Written on

·

289

0

  useEffect(() => {
    function onScroll() {
      console.log(window.scrollYdocument.documentElement.clientHeightdocument.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하면 작동할때도 있고 안할때도 있고.. 코드들은 다 문제없는데 뭐가 문제인지 모르겠네요 

reduxexpressreactnodejsNext.js

Answer 1

1

zerocho님의 프로필 이미지
zerocho
Instructor

=== 대신 > 를 쓰고

documentElement.scrollHeight - 1을 하면 될것같습니다. 어쨌든 식만 성립하면 됩니다.

nicealice991462's profile image
nicealice991462

asked

Ask a question