How to remove listening scrolling events in react

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)"
        }
    })
}
Mar.15,2022

if you want to remove the event addEventListener , the executor must use an external function instead of an anonymous function as you do

const onScroll = () => {

};

//
window.addEventListener('scroll', onScroll);

//
window.removeEventListener('scroll', onScroll);

define a component method and then use it on the hook of the component life cycle.

{
    doSomething(){},
    componentDidMount(){
        window.addEventListener('scroll', this.doSomething)
    },
    componentWillUnmount(){
        window.removeEventListener('scroll', this.doSomething)
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3df92-2c3ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3df92-2c3ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?