How to Develop Mobile Apps on React Native Using Expo CLI

How to Develop Mobile Apps on React Native Using Expo CLI

React Native is a JavaScript-based, cross-platform mobile application development framework that helps developers build native mobile applications for iOS and Android with a single codebase. Gone are the days of learning two different programming languages and frameworks for developing iOS and Android apps.

Prominent organizations like Facebook, Instagram, Uber Eats, and Pinterest use React Native to power mobile applications. Therefore, the opinion that only native languages on tools like Swift, Java, and Kotlin can create high-performance native mobile applications is flawed.

Developing apps on React Native takes two methods: the Expo(CLI) and the React Native CLI. The Expo CLI method is the best starting point for beginner developers because of its ease of use and beginner-friendly tools.

This guide will show developers the essentials needed to create mobile applications on React Native using the Expo CLI method. At the end of this article, you will have a working developer environment, recommended tools setup, and requirements for creating your first mobile applications on React Native.

What is Expo CLI?

Expo CLI is a command line tool that serves as the interface between developers and other Expo tools. It simplifies the process of setting up and deploying projects and provides access to other helpful tools like an expo-SDK library, various device emulators, and a code editor.

Requirements

Before building an app, developers need some components for a working environment.

  • Node.js LTS release: You should install the Node.js LTS release on your machine to run certain commands.

  • Git

Recommend Tools

  • Text Editor: A code editor is a must-have tool for any developer. Visual Studio Code and Sublime Text are some of the most popular text editors for developing React Native apps.

  • Yarn: Yarn helps developers install and manage packages. You can install it using your package manager or by running the command below:

      npm install --global yarn
    

Setting up Your Environment

The first step to using Expo CLI is to install the Expo CLI utility tool and a mobile client application, Expo Go, which opens your project on iOS and Android platforms. The Expo Go is available on the App Store and Play Store.

Ensure that your environment is set up correctly. To do this, open your terminal and run the npx command. Developers can bypass downloading Expo by running:

npx expo -h

Once the installation is complete, check which Expo account is authenticated to your environment by running:

npx expo whoami

If your account is logged in, it is safe to proceed. If not, register your Expo account by running:

npx expo register

Download Extensions

Using VS code, you can install some extensions to help you work more efficiently. Go to "Extensions" or use Ctrl + Shift + X to get some helpful extensions for this project. The following extensions are essential for you:

  1. React Native Tools: This tool helps to debug and integrate commands for React Native.

  2. React Native/ React/ Redux Snippets: This extension offers code snippets for React-Native/React/Redux es6/es7 and flowtype/typescript, Storybook.

  3. Prettier: This extension offers a consistent style by parsing codes and re-printing them with its own rules, taking the maximum line length into account, and wrapping code when necessary.

  4. Material Icon Theme: This extension designs your material icons. Use "Format on Save" in preferences. VS Code will enable this extension for your project.

Creating Your Mobile Application

Now that your environment is set up correctly, you can start creating your first mobile application on React Native using Expo CLI.

Initialize the project

We would name our project my first mobile app. Begin by initializing a new project with the following command:

npx create-expo-app my-first-mobile-app

Next, navigate to your project directory.

cd my-first-mobile-app

Choose your preferred workflow

Select the workflow you want for this project. In React Native, there are two main options to consider:

  1. Managed Workflow: This workflow offers other categories. That is, the "Blank," "Blank (TypeScript)," and "Tabs" options. The Blank is a minimal app that offers a clean canvas for developers to use. Blank (TypeScript) is the same as the blank option but comes with TypeScript configurations. The Tabs option offers several example screens and tabs using React navigations.

  2. Bare Workflow: This workflow is a barebone React Native project with no extra support from Expo CLI. It is more suitable for advanced developers who can handle iOS and Andriod Projects. This workflow offers two categories. That is, the "Minimal" and "Minimal (TypeScript)" options. The minimal offers only the essentials you need for the project. The Minimal (TypeScript) option is the same as Minimal but comes with TypeScript configurations.

You should choose the Managed Workflow because it allows Expo CLI to handle the complexities of dealing with iOS and Android projects. Here, you will use pure JavaScript, which is much easier to learn and manage for beginners. Select "expo-template-blank" and npm will install it. Then cd into the folder to start coding your project.

Start the development server

Start your development server by typing expo start into the command line. After that, a terminal window will open and link you to the development server. Before going any further, ensure your device is connected to the same network as your computer.

npx expo start

When you run the server, Expo CLI initiates a Metro Bundler, which is the HTTP bundler that compiles the JS code in Babel and sends it to the Expo Go App. It enables you to code in one language and deploy for multiple platforms. Additionally, it provides an app with live reload capabilities so you can view your changes as soon as they are implemented.

Open the App on your Device

There are several ways to view your app on a mobile device. You can choose:

  1. Run on iOS simulator/Android device emulator.

  2. Run on a web browser

  3. Send link with an Email

  4. Publish or republish projects on Expo (However, this option is only for testing purposes, not production).

Conclusion

Creating mobile applications on React Native using Expo CLI is a beginner-friendly and efficient way to create apps. With the help of this method, you can develop mobile applications almost effortlessly and in no time. So if you’re looking to start building mobile apps with ease, try the Expo CLI method today!