Home > Net >  Facing this error "Unexpected use of 'scrollY' no-restricted-globals" in reactjs
Facing this error "Unexpected use of 'scrollY' no-restricted-globals" in reactjs

Time:08-22

I searched for it but did not find any good answer for this. like people saying that add scrollY:true to ESLint config file and did not tell where I could do these configuration and where the eslint config file is? Please help me.

This is my Navbar.jsx component.

const Navbar = () => {
    window.addEventListener('scroll', () => {
        if (window.scrollY > 100) {
            console.log('hello');
        }
    })
    return (
        <nav className='w-full py-3 flex justify-between items-center fixed top-0 z-50 nav' >
            <div>Hello</div>
        </nav >
    );
}

export default Navbar;```



[![The error which my terminal is displaying][1]][1]


  [1]: https://i.stack.imgur.com/ptSen.png

CodePudding user response:

In that case you have to create an eslint configuration file in the project's root folder, if not already present. You can create it by simply creating an json file and naming it

.eslintrc.json

"globals": {
    "scrollY": true
}

Here's the official link to understand - ESLink Docs - Specifying Globals

  • Related