componentDidMount is executed before <Head /> inside render #12196
Unanswered
vinitgundeti
asked this question in
Help
Replies: 1 comment
-
Since I wasn't able to test with the scripts in your example, I ran this test: export default class Video extends React.PureComponent {
componentDidMount() {
console.log(window.google);
}
render() {
return (
<div>
<Head>
<title>play</title>
<script
src={`https://maps.googleapis.com/maps/api/js?key=${API_KEY}&libraries=places`}
async
></script>
</Head>
<div className="player-container"></div>
</div>
);
}
} and I saw that when I had Have you tried this? Otherwise, could you include the scripts you mentioned so it could be fully reproduced as you have it? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to use an external script instead of adding script tag in _document.js i need to add it in page where script is required.
I have added script tag inside
<Head>
in my page and handled configuration of external script inside componentDidMountbut the page is crashing with error the variable is not defined
the error is occured because the variable is defined inside script and the script is not loaded
To Reproduce
in above code MyPlayer is defined in external script
if you run this first time it will say MyPlayer is not defined and the title will also won't set
but after reloading the page it works
Expected behavior
componentDidMount need to execute after script loads so that i can get MyPlayer Object
System information
Beta Was this translation helpful? Give feedback.
All reactions