it"s OK to listen for scrolling events in componentDidMount in the following code, but there is a remove listening event in componentWillUnmount when I jump to another page. Is there any way to solve it?
componentDidMount () {
//
window.addEventListener("scroll", () => {
console.log("");
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
const header = document.body.querySelector(".headerStyle")
if (scrollTop > 100) {
header.style.backgroundColor = "-sharpFF8949"
} else if (scrollTop < 100 || scrollTop == 0) {
header.style.backgroundColor = "rgba(0,0,0,0)"
}
})
}
componentWillUnmount() {
//
window.removeEventListener("scroll", () => {
console.log("");
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
const header = document.body.querySelector(".headerStyle")
if (scrollTop > 100) {
header.style.backgroundColor = "rgba(247, 247, 247, 1)"
} else if (scrollTop < 100 || scrollTop == 0) {
header.style.backgroundColor = "rgba(247, 247, 247, 1)"
}
})
}