I need to add a div
& async script
at the bottom of the page in my react
application.
1st Try:
...
...
render() {
return (
<div>
<HeaderComponent />
<Notifications />
{children}
<FooterComponent />
<div
className="cc-banner-embed"
data-config="YmFja2MGVUJhY2tncm91bmQ9dHJ1ZQ==">
<script async src="https://banner.crowdcube.com/embed.js"></script>
</div>
</div>
);
}
2nd Try:
...
// use lifecycle method to load script
componentDidMount() {
const s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://banner.crowdcube.com/embed.js";
this.instance.appendChild(s);
}
render() {
return (
<div>
<HeaderComponent />
<Notifications />
{children}
<FooterComponent />
<div
className="cc-banner-embed"
data-config="YmFja2MGVUJhY2tncm91bmQ9dHJ1ZQ=="
ref={el => (this.instance = el)}>
</div>
</div>
);
}
Unfortunately, both of these didn't work. How do I get this script file to load async.
EDIT: My code was actually correct, however, in this case, the browser for some reason wasnt displaying it (cookie issue maybe). Going in incognito did the trick. Thank you.