Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect if the script is already loaded? #6

Open
daveyx opened this issue Jun 18, 2017 · 6 comments
Open

How to detect if the script is already loaded? #6

daveyx opened this issue Jun 18, 2017 · 6 comments

Comments

@daveyx
Copy link

daveyx commented Jun 18, 2017

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?

@andresin87
Copy link

andresin87 commented Jun 20, 2017

#5

...solves that problem.

@daveyx
Copy link
Author

daveyx commented Jun 21, 2017

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?

@andresin87
Copy link

If the props are changed (typeOf [prop] !== 'function'), It will call onLoad()again @daveyx. That's right.

@daveyx
Copy link
Author

daveyx commented Jun 27, 2017

thx @andresin87 any plan for next release in npm?

@jakubkottnauer
Copy link
Contributor

Hi @daveyx and @andresin87, we'll make a release as soon as that PR is merged.

@matejlauko
Copy link

@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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants