React Native Important Commands

React Native is a popular framework for building mobile applications using JavaScript and React. To work with React Native, you’ll often use the command-line interface (CLI) to perform various tasks. Here are some of the popular commands and their descriptions:

  1. Create a New React Native Project:
    > npx react-native init MyApp
    This command initializes a new React Native project called “MyApp” in the current directory.

  2. Start the Development Server:
    > npx react-native start
    This command starts the Metro Bundler, which is the development server for your React Native app.

  3. Run the App on an Android Emulator:
    > npx react-native run-android
    Use this command to build and run your React Native app on an Android emulator.

  4. Run the App on an iOS Simulator:
    > npx react-native run-ios
    This command builds and runs your React Native app on an iOS simulator. You can specify a specific simulator with the --simulator flag.

  5. Install a New Dependency:
    > npm install package-name
    > yarn add package-name

    You can use npm or yarn to install javascript packages or libraries into react-native projects. If you are using yarn, you can use the second command.

  6. Link Native Modules:
    > npx react-native link
    If you are using a react-native library of version less than 0.64, then you need to run the above command just after adding new font family, packages.

  7. Generate a Release Build (Android):
    > cd android && ./gradlew bundleRelease
    This command generates a release bundle for your Android app. But You’ll need to configure signing and other release settings in your Android project such as generating keystore files for release mode.

  8. Generate a Release Build (iOS):
    > npx react-native run-ios --configuration Release
    This command generates a release build for your iOS app. You’ll need to configure signing and other release settings in your Xcode project.

  9. Generate a Release Build (Android):
    > npx react-native run-android --variant release
    This command runs your project in your real device or emulator in release mode, but your app should have a keystore file linked with your project in release mode.

  10. Create a Release APK (Android):
    > cd android && ./gradlew assembleRelease
    If you have created a keystore file in release mode then, This command creates a debug APK for your Android app, which you can send for testing.

  11. Clear npm cache forcibly:
    > npm cache clean --f
    This command clears all npm-related cache from the project forcefully. sometimes this command helps a lot to solve cache issues.

  12. Install dependencies in IOS:
    > pod install
    This command is very necessary command if you are running your React native project on Mac. This project is run just after you install JavaScript libraries.

Leave a Reply

Your email address will not be published. Required fields are marked *