VScode is highlighting lines that use document
and history
as undefined per my linter rules.
How to get these to be recognized as valid?
C
You can use the globals directive to specify variables which are defined globally.
However, you shouldn't need to access document
or history
directly in a React app in the first place.
Generally you should interact with the history
only through the use of a router, and you should avoid direct DOM access entirely.
The main things you want want to use direct DOM access for are changing things in the <head>
which are better handled with React Helmet or for manipulating content of a component which should almost always be done through state and props and where the rare exceptions should be handled via a useRef hook instead of searching the document via document.querySelector
or similar.