react-load-script
react-load-script copied to clipboard
How to detect if the script is already loaded?
Hi, i use react-load-script to load a script in a component. If this component is instantiated a second time, i wanna detect if the script was loaded before.
Does react-load-script support this functionality?
https://github.com/blueberryapps/react-load-script/pull/5
...solves that problem.
means i don't have to care about it, as of
if (this.constructor.loadedScripts[url]) {
onLoad();
return;
}
onLoad() will also be called in my second instantiation after the script was successfully loaded, right?
If the props are changed (typeOf [prop] !== 'function'), It will call onLoad()
again @daveyx. That's right.
thx @andresin87 any plan for next release in npm?
Hi @daveyx and @andresin87, we'll make a release as soon as that PR is merged.
@daveyx The current version already calls onLoad() every time the component has been mounted.
So to detect if the script was loaded before, the best would be to track inside your app state if onLoad has been called.
Or you can do:
const isLoaded = Script.loadedScripts[url]