'How to log window.scrollY value on console with next js?

For some reason my ScrollToTop component is not working as expected in my app. I have tried to debug the matter in all ways that i know but i cannot figure out why the component do not log value of scrollY as expected. I tried to move the snippet below in other component of my app but same result. I tried to call the toggleVisibilty function but it only log 0 once then nothing else. Can someone tell me what can cause such error, please? thanks

 const toggleVisibility = () => {
      console.log(window.scrollY)
      // window.pageYOffset >= 300 ?
      // setisVisible(true) :
    
      // setisVisible(false)
      // console.log(window.pageYOffset)      
    };
    //toggleVisibility()
    // const scrollToTop = () => {
    //   window.scrollTo({
    //       top:0,
    //       behavior: "smooth",
    //   });
    // };
    
    useEffect(() => {
      window.addEventListener('scroll', toggleVisibility, {passive: true});
      return () => window.removeEventListener('scroll', toggleVisibility);
      
    
    });


Solution 1:[1]

I found what was my mistake. my html and body had a height property rather than a min-height in my css file. When changed this it worked fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leo