Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking a React-Native application into plugable modules

I am looking to write a React-Native application. I want to be able to download new modules at run-time on the device to extend functionality. There would be some core logic that knows how to request new modules based on some form input like a dbs. I do not want to bundle everything into a single monolithic bundle which is what I believe happens now with the built in packager.

This would something similar to how RequireJS works in browser. What I need to know is:

  1. How do I build independent modules? react-native bundle doesn't seem to allow me to select which root modules to begin with and only works on root project
  2. How can I at run-time request new functionality be injected into the current JavaScript environment?
like image 620
Bob9630 Avatar asked Aug 14 '15 22:08

Bob9630


People also ask

Can I use react modules in React Native?

No, React uses HTML tags to render while React Native uses an abstraction over platform native views. They're not compatible.

How do you integrate native modules in React Native?

To add native modules to react-native, let's create a new Kotlin class named 'NativeModuleManagerPackage'. We will implement ReactPackage in this file which will expose our native code to react-native. For registering the NativeModuleManagerPackage , we have to add code in MainApplication.

CAN node modules be used in React Native?

So why does one need Node core modules to work in React Native? The answer is cross-platform code and the vast npm ecosystem. It's convenient to be able to use the same modules in React Native as in Node and browsers.


1 Answers

React native starts by pointing at a JS bundle. This means that you would at least have to restart the app to reload the js bundle (assuming that you're reading it from a server and not from the ios device itself).

If you did have a way to update the js files on the server (through some sort of web service that updated based on things the user does) then restarting the app could theoretically reload the JS and provide new functionality to the app.

like image 122
Braden Avatar answered Oct 23 '22 14:10

Braden