I'm using reactjs to develop a front end, I want to get the heigth of my screen so I can use overflowY: scroll
, but when I use screen.heigth
, an error came out:
Unexpected use of 'screen' no-restricted-globals
I also used window.location.heigth
and nothing happened.
To fix the 'No restricted globals' ESLint Error when developing a React app, we can add the // eslint-disable-next-line no-restricted-globals comment before the code that is causing the error. But the better solution is to put window before the variable that causes the error.
Rule: no-restricted-globalsDisallow specific global variables. Disallowing usage of specific global variables can be useful if you want to allow a set of global variables by enabling an environment, but still want to disallow some of those.
This eslint rule warns you about using a global variable. There might be an issue with shadowing or you simply forgot to declare. So you have to be explicit and access it starting window
window.screen.height
Assuming you have created your project using CRA. Read this section of docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With