Is componentDidMount() called after the HTML page is fully loaded?


(Dantenovski) #1

By fully I mean including scripts at the bottom of the page. I’m invoking a JS code from within componentDidMount() but the code only works in conjunction with JS files placed at the bottom of the HTML page and only after those JS have been fully loaded. It seems like the JS code invoked from componentDidMount is called before all other scripts are loaded.


(Jakob Lind) #2

componentDidMount is run when the React component is mounted. It does not know about other things on the page. It might happen that componentDidMount will be run before all other scripts are loaded. Especially if other scripts are loaded async.

So you might need to rethink how to solve your task. Could you put the external scripts in your JS bundle for example?


(Dantenovski) #3

Thank you! Yes, that’s what I thought too, just wanted to make sure I got it right