How to load an external scripts
See original GitHub issueHello,
Today I’m try to use the react-storybook
for building a component thats use the SDK of Facebook. I will try something like this:
componentWillMount() {
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
And I did not succeed. The script loads up if I see on the network of browser. But it is not accessible through the console or even within React functions.
I believe it can be related to how the encapsulation react-storybook
works.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to Load External JavaScript Files From the Browser ...
Using appendChild() is a more useful way to load an external script file. Instead of overwriting the loaded page with document.write() , ...
Read more >HTML script src Attribute - W3Schools
The src attribute specifies the URL of an external script file. If you want to run the same JavaScript on several pages in...
Read more >The best way to load external JavaScript - Human Who Codes
The best technique · Create two JavaScript files. · Include the first JavaScript file with a <script> tag at the bottom of the...
Read more >How to load an external JavaScript on a condition
The question is how to rewrite a static HTML-code into JavaScript which decides whether to load the script and loads it programmatically.
Read more >How to Load External Scripts Dynamically In Angular
The easiest way to add external dependencies to your Angular projects is through npm. The second best option is to add script tags...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Leaving this snippet here for anyone who may have a similar need to load scripts per-story:
I need something like what @adamellsworth described, but his code didn’t seem to work. While I didn’t get any errors, my stories weren’t actually loaded at runtime.