I'm working on retrieving the scroll position using the code snippet below:
useEffect (()=>{
document.addEventListener("scroll", e => {
let scrolled = document.scrollingElement.scrollTop;
if (scrolled >= 5){
setPos("moved")
} else {
setPos("top")
}
})
},[])
However, Typescript is flagging an issue with the document.scrollingElement.scrollTop property, suggesting that it could possibly be null. How can I address this error and ensure Typescript remains satisfied?