I am new to React Native I want to know how is it possible to deploy react native part or code like javascript files and assets on server and then use it.
Currently it is showing as localhost
Please let me know how to deploy it on server also is it possible or not.
Do I need to update app on play store every time when I change something in react part of my code?
what exactly code push does and is there any way by which I can load my react native bundle from server and update app dynamically
I am new to React Native I want to know how is it possible to deploy react native part or code like javascript files and assets on server and then use it.
Currently it is showing as localhost
Please let me know how to deploy it on server also is it possible or not.
Do I need to update app on play store every time when I change something in react part of my code?
what exactly code push does and is there any way by which I can load my react native bundle from server and update app dynamically
Share Improve this question edited May 31, 2018 at 9:18 amodkanthe asked May 30, 2018 at 7:46 amodkantheamodkanthe 4,5306 gold badges42 silver badges86 bronze badges 5- not possible, your react-native code must be compiled to the native Android app or native ios app. And then you need to publish your app to the apple store or google store. But if your app needs to download some resources (image, media, json ..) you can put these resource on a server. – Alex Nguyen Commented May 30, 2018 at 7:54
- so do need to update app every time I change something in react native code – amodkanthe Commented May 30, 2018 at 7:56
- it depends on your code ( design). if your code can detect the change from the remote config file and apply it, you dont need to update your app every time on app store. – Alex Nguyen Commented May 30, 2018 at 8:03
- how to do this if your code can detect the change from the remote config file any example on this ? – amodkanthe Commented May 30, 2018 at 8:05
- github.com/redbooth/react-native-auto-updater => this is simple example – Alex Nguyen Commented May 30, 2018 at 8:07
3 Answers
Reset to default 8React-native compiles down to the two native languages. Effectively you have 2 applications, non of them web.
You could have an image assets remote on a server and use the URL in the react-native code combined with a cache (so you don't have to download the asset every time).
Considering JavaScript files, I would say no. Unless you create an server and request the functionality by API calls.
And no, you don't have to interact with the play store every time, but usually you do :)
I think you need to understand how React Native works in order to understand.
What RN actually does is to expose native API to your Javascript code base. Basically a RN App is composed by 2 things:
As you can immagine the Native part is everything that is written in Swift/ Objective-C/ Java
and that is the part you can not update without going through the App stores.
Now the interesting thing is the JS part, remember we said that basically you are consuming native API with JS. If you notice when you run react-native run-ios
or react-native run-android
a server is instanced which serves a bundle to your emulator / physical device.
Now if you think about it basically when you open the App the bundle is downloaded an then run. When you update your codebase while the app is running on the emulator the servers sends a signal trough the socket to notify the client that an update is available. At that point the client downloads the bundle and the app is reloaded.
Now to answer your question, yes you can serve the JS Bundle on your server and make the app check when is loaded or resumed if a new version of the JS Bundle is available, if so to download it (OTA update). As you can understand only the Javascript part can be update in this way and not the native part as well.
Then again, there are a few services that already do this like codepush by MS.
You can use the code-push cli or appcenter cli to publish your Javascript code to the cloud servers (hosted by Microsoft), and use react-native-code-push to retrieve the updates in your RN app.
Alternatively, you can use Expo which comes with its own over-the-air (OTA) update functionalities.
Both of the above services manage their servers internally for you and do not allow you to host the JS bundle on your own server (though there's a feature request for it).
Note that only changes to the Javascript codebase can be delivered OTA. Any updates to native code (eg. Swift/Java) must still be delivered through App Store/Google Play.