4

Is it possible to load a component into a bundled react-native app dynamically and from an external URL?

Example of what I eventually want to achieve

const id = await fetch('http://example.com/getid/');

import CustomModule from `http://example.com?id=${id}`

export default class App extends React.Component {
  render() {
  return (
    <View style={styles.container}>
      <CustomModule />
    </View>
  );
 }
}
imana97
  • 400
  • 2
  • 10

1 Answers1

-1

Importing of external URL Component is not possible as of today.

If you have a Component hosted on an external Link, clone/copy/download that in your Project and import that.

or

If you have a set of common components, you can host them on a private npm registry and then add them in package.json and import them in your code.

Ayushya
  • 1,862
  • 1
  • 10
  • 15
  • thank you. I know that. I am trying to build an app that developers can dynamically add their plugins (components) and the app can load those components without updating the app source code. – imana97 Sep 18 '18 at 18:27
  • I'm not sure if I understood you but if you meant live updates without pulishing the app again that's possible, but in another way, "live push" or "live updates" there are a couple of services that allow you to do that like CodePush https://learn.microsoft.com/en-us/appcenter/distribution/codepush/react-native and Expo OTA https://docs.expo.io/versions/latest/guides/configuring-ota-updates – Chris Gomez Sep 18 '18 at 18:33
  • thank you. I am aware of OTA updates. The problem is, in OTA, for each change, the entire app needs to be updated and pushed. If I can get components from a URL, then I don't need to update the entire app. I have done this using angularJS. There you can `eval()` JS code and then $compile them to become new directives. But I can't do the same with react-native. My example in the question explains what I want to achieve. I don't want to update the entire app over OTA, I just want to fetch the component dynamically and from an external URL. -Best – imana97 Sep 18 '18 at 18:48
  • 1
    how did you go with this @imana97? Keen to hear your results. – Steve Pascoe Jan 08 '19 at 10:21
  • @StevePascoe Unfortunately, no one could answer this question yet. I discussed this offline with many folks and no one has the best solution. It seems like what facebook has created to compile react-native code is sort of a mystery. Someone told me to fork Expo and use their code-push mechanism to update the entire code base with the new components. Apart from that, I don't have any other solution. – imana97 Jan 09 '19 at 23:00