ReactNative - Why does a React Native App need to connect to Local Host?

1.2k Views Asked by At

I have been reading a book on React Native that builds a simple React Native App for IOS in the first few chapters. When compiling and running the project in Xcode, a packager runs in the background and I can also see my app trying to connect to local host.

My understanding is that React Native converts JSX elements to platform specific views. So my question is why does the App need to connect to a server and what is the purpose of the packager running in the background?

Also, how is running the app on an Xcode simulator different from deploying it on the app store?

I have tried to look online for answers, but no one has addressed them. It seems everyone is taking it for granted that all this is obvious.

2

There are 2 best solutions below

0
On BEST ANSWER

After looking for an answer, I stumbled upon the following guide from Facebook that answers a different question but also addresses mine indirectly.

So apparently, the localhost is a development server used to link your javascript code to the app, which you use if you are testing on a physical device or a simulator. So the question that comes to one mind after reading this is why not bundle that javascript code with the compiled IOS files? Well, it is best to keep them separate because it enables you to simply change your javascript code from your computer and have it automatically sync with your IOS app.

Now, when it comes to deploying to the app store, you will need to bundle the javascript code and remove the implementation part where it connects to a localhost, which, again, is used for debugging purposes.

0
On

You answered your own question it appears! In development mode, the JavaScript bundle is served from the react-native packager server on your machine.

When making a release for the App Store and Google Play, the JavaScript is minified and bundled into the app file (.ipa/.app for iOS, .apk for Android).

Running the app in release mode is possible from Xcode. Depending on how your project is set up, release mode could be a different target, a different scheme within one target, or a build configuration within a target's scheme. For more on iOS targets/schemes, see: Xcode: What is a target and scheme in plain language?