Skip to content

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

Description

@daveyx

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?

Activity

  1. andresin87 commented on Jun 20, 2017

    @andresin87

    #5

    ...solves that problem.

  2. daveyx commented on Jun 21, 2017

    @daveyx
    Author

    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?

  3. andresin87 commented on Jun 26, 2017

    @andresin87

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

  4. daveyx commented on Jun 27, 2017

    @daveyx
    Author

    thx @andresin87 any plan for next release in npm?

  5. jakubkottnauer commented on Jul 7, 2017

    @jakubkottnauer
    Contributor

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

  6. matejlauko commented on Aug 3, 2017

    @matejlauko

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions