Learning react here!
I'm trying to access a global variable that is exposed by a browser extension that I'm utilizing. The first thing that I'm doing is in the componentDidMount method I'm checking to see if the variable is available or not.
Every time I try to do that by simply adding an if condition in componentDidMount it fails. But if I wrap the if statement in
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
it works fine. I thought that the componentDidMount would have done the trick rather than wrapping my condition check in the code above.
Am I missing something here? Is there a better way to check if the app has completely rendered and it will have access to the global variables provided by the browser?
Thanks!