I have been using react native for a couple months now. However, I really don't know the difference between the starting commands. Currently, I use npm on my project. However, I know yarn can be used. These are the commands I really don't understand the difference with:
exp start, exp ios, exp android
react-native run-ios, react-native run-android
npm start, npm ios, npm android
Which ones are better in what cases and why? Currently, I am using exp but others use react-native run-ios. I used to use npm ios.
Thank you in advance.
It might help to have an overview of the React Native architecture.
In react native, when you write, say, <View/>
, it gets sent across the bridge to the native code and dynamically translated into UIView
on iOS or android.view.View
on Android. Every basic component in the react-native
package has been implemented this way. If you want additional native functionality on both platforms, say a library which uses native map components, you will end up having to include the native libraries separately into your Android build.gradle
and your iOS .xcodeproj
.
The exp
CLI is used to start apps built with the Expo SDK. Expo is essentially a prebuilt app with a certain set of native components already included for convenience; all you supply is your JSX; thus the recommendation to "eject" to a regular react native app if you need to use any other libraries.
react-native run-ios
and run-android
builds the native .app
or .apk
using the iOS or Android toolchains, starts the Metro Bundler, which minifies and serves the JSX and other assets such as images over to your device in debug mode (You might see something like Loading from localhost:8081
).
On Android, it starts the adb
server to push the APK with all the native libraries included onto your device, if you have USB debugging enabled. run-ios
does the same with the .app
; if you install to a simulator it has automatically configured AppDelegate.m
to communicate with localhost:8081
, whereas live reload over USB has to be configured manually on a physical device.
react-native start
simply starts the Metro bundler, which is useful if you already have the app installed.
Commands that begin with npm
are defined as scripts in your package.json
file. As of RN 0.57, npm start
simply calls node node_modules/react-native/local-cli/cli.js start
; which is the same as running react-native start
; according to the docs react-native-cli
installed separately will call the locally installed version of the CLI in node_modules
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With