File structure
src/components: contains reusable UI or small sections of the user interface.src/navigation: contains the logic to move between screens.src/screens: contains large components, similar to a web page each file in here represents an entire mobile phone screen.src/utils: for utility functions or any function not related to rendering components or functions that can be used by multiple components.
The package.json file contains all the dependencies and modules/libraries the app requires.
Getting Started
Note: Make sure you have completed the React Native - Environment Setup instructions till "Creating a new application" step, before proceeding.
Step 1: Start the Metro Server
First, you will need to start Metro, the JavaScript bundler that ships with React Native.
To start Metro, run the following command from the root of your React Native project:
# using Yarn
yarn startStep 2: Start your Application
Let Metro Bundler run in its own terminal. Open a new terminal from the root of your React Native project. Run the following command to start your Android or iOS app:
# using Yarn for Android
yarn android
or
# using Yarn for iOS
yarn iosIf everything is set up correctly, you should see your new app running in your Android Emulator or iOS Simulator shortly provided you have set up your emulator/simulator correctly.
This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.
Step 3: Hot Reloading
Now that you have successfully run the app, here is how to quickly build and run your changes on the emulator or phone and see your changes quickly.
-
Open
App.tsxin VS Code and edit some lines. -
Save the file.
-
For Android: Press the R key twice or select "Reload" from the Developer Menu (Ctrl + M) to see your changes!
For iOS: Hit Cmd ⌘ + R in your iOS Simulator or Cmd ⌘ + M (on macOS) or shake your phone!