The issue at hand is quite simple:
An error occurred because I tried to compare a number with a 'Ref<number>' object.
It seems ridiculous that I can't compare two numbers, but as I am new to Typescript, I would greatly appreciate some guidance. Here's the code snippet:
// Scroll logic:
let lastScroll = ref<number>(0)
const handleScroll = () => {
const body = document.body
window.addEventListener('scroll', () => {
const currentScroll = window.scrollY
if (currentScroll <= 0) {
body.classList.remove('scroll-up')
}
if (
currentScroll > lastScroll &&
!body.classList.contains('scroll-down')
) {
body.classList.remove('scroll-up')
body.classList.add('scroll-down')
}
if (
currentScroll < lastScroll &&
body.classList.contains('scroll-down')
) {
body.classList.remove('scroll-down')
body.classList.add('scroll-up')
}
lastScroll = currentScroll
})
}
The problem resides in the if() statement: https://i.sstatic.net/M2ZHy.png