react-async-script-loader icon indicating copy to clipboard operation
react-async-script-loader copied to clipboard

Dynamic script urls (from props)

Open cdelaorden opened this issue 7 years ago • 3 comments

This library is pretty useful as it is, but having the option to dynamically generate the script URLs based on props would make it more generic.

Example use case: you want to load an API library (say Google API) but want to dynamically inject the API_KEY based on config fetched from server, or logged in user permissions/profile, and so on.

Basically being able to do something like:

const Enhanced = AsyncScriptLoader(props => {
  return [
          'https://ajax.googleapis.com/ajax/libs/jquery/' +
            props.version +
            '/jquery.min.js'        
  ]
})(MyComponent)

// later on
<MyComponent version='3.0.0' />

In addition this will make this library play much nicer with recompose in which a stream of props is generated from HOC to HOC.

Pull request to follow :)

cdelaorden avatar Jan 12 '18 15:01 cdelaorden

Hey! I'm also looking for a way to use props to dynamically create URLs.

Will this be merged or is there any way to achieve the same result?

Thanks in advance!

manelet avatar Feb 13 '18 12:02 manelet

has this been resolved? I need it also to create dynamic URL for apiKey. can this resolve the issue --> https://stackoverflow.com/questions/43351122/building-a-component-which-depends-on-a-3rd-party-script

Thanks anyway for the amazing library!

dgana avatar Mar 17 '19 12:03 dgana

Any updates regarding this? Or are there any workarounds?

annshress avatar Sep 09 '19 17:09 annshress