Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected use of 'screen' no-restricted-globals reactjs

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.

like image 511
Jalloul95 Avatar asked Apr 27 '18 08:04

Jalloul95


People also ask

How do I fix no restricted Globals?

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.

What is no restricted Globals?

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.


1 Answers

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

like image 164
Yury Tarabanko Avatar answered Oct 16 '22 10:10

Yury Tarabanko