leozdgao / react-async-script-loader

A decorator for script lazy loading on react component
MIT License
258 stars 55 forks source link

Dynamic script urls (from props) #29

Open cdelaorden opened 6 years ago

cdelaorden commented 6 years ago

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 :)

manelet commented 6 years ago

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!

dgana commented 5 years ago

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!

annshress commented 5 years ago

Any updates regarding this? Or are there any workarounds?