Introduction to Expo and React Native
7 min read
1. The "Why" Before the "How": Understanding the Expo Ecosystem
Definition: React Native is an open-source UI software framework created by Meta that allows developers to write mobile applications using JavaScript and React. Expo is a framework and platform built on top of React Native that provides a set of tools, libraries, and services to simplify the development process.
The Problem:
Historically, building a mobile application meant writing Swift or Objective-C for iOS, and Java or Kotlin for Android. If you wanted an app on both platforms, you had to build it twice. React Native solved this by allowing JavaScript to control native user interface elements.
However, early React Native introduced a new nightmare: the setup. Developers had to manually link third-party native libraries, configure Gradle files for Android, wrestle with CocoaPods for iOS, and manage complex build environments. Upgrading versions often felt like trying to defuse a bomb with a blindfold on.
The Solution:
Expo solves this by acting as the Next.js of React Native. It abstracts away the complex native tooling.
When you use Expo, you don't need to open Xcode or Android Studio for day-to-day tasks. Expo provides a curated, guaranteed-to-work-together set of native libraries (for camera, file system, notifications, etc.). It also introduces Continuous Native Generation (CNG), which dynamically generates the native iOS and Android project folders on the fly so you never have to manually touch them.
Flow Context:
Imagine you want to drive a car. Building with bare React Native is like receiving a car in individual parts—you have to assemble the engine, attach the wheels, and wire the dashboard before you can drive. Using Expo is like buying a fully assembled car from a dealership; you just get in, adjust the mirrors, and turn the key.
2. Setting Up Your Environment: Node.js, Watchman, and Expo CLI
Definition: The environment setup consists of the runtime (Node.js), a file watcher (Watchman), and the command-line interface used to scaffold the project (create-expo-app).
The Problem:
Your computer’s operating system cannot natively run React or bundle mobile JavaScript applications out of the box. When you write code, you need a way to instantly bundle thousands of files into a single readable package and push it to your phone whenever you hit "Save". If the process is slow, your development experience suffers.
The Solution:
We install specific tools to handle this pipeline.
- Node.js (v20+ LTS): The JavaScript runtime that allows JavaScript to run on your computer (outside of a browser). It powers the Metro Bundler, which packages your code.
- Watchman: A tool developed by Meta that exists solely to watch files and record when they change. While optional, it is an industry standard on macOS and Linux to prevent the Metro Bundler from crashing or consuming 100% of your CPU when watching thousands of files inside
node_modules. - Expo CLI: The command-line interface to create and manage your app.
Industry Practice Note: In the past, developers installed global tools (like npm install -g expo-cli). This is no longer the industry standard because global packages become outdated quickly. Today, we use npx to fetch and execute the absolute latest version of the CLI dynamically.
Step-by-Step Setup:
- Install Node.js from their official website (ensure you pick the LTS version).
- (Mac users) Install Watchman using Homebrew:
brew install watchman. - Open your terminal and run the scaffolding command:
npx create-expo-app@latest my-awesome-appWhen prompted, you can just accept the default template. In modern Expo releases, the create-expo-app defaults to using Expo Router, a powerful file-based routing system (similar to Next.js app/ directory), and comes pre-configured with TypeScript.
Once the installation finishes, navigate into your new fortress:
cd my-awesome-app3. Your First App: "Hello World" in Expo Go
Definition: Bootstrapping is the process of starting the development server and rendering your first visible component on a physical device or emulator.
The Problem:
You have a folder full of files, but staring at text in a code editor isn't a mobile app. You need a way to view the code dynamically on a screen and verify that your environment is working.
The Solution:
Expo provides a local development server and a companion app called Expo Go. By running a single command, you start the server, which generates a QR code.
Run this in your terminal:
npx expo startWhat happens under the hood:
The Metro Bundler spins up on your local network. It acts like a fast-food kitchen. When you request the app on your device, the bundler rapidly cooks up all your JavaScript files, wraps them into a single bundle, and serves them over your local Wi-Fi.
How to see it:
- Download the Expo Go app from the iOS App Store or Google Play Store on your physical phone.
- Make sure your phone and computer are on the exact same Wi-Fi network.
- If you are on an iPhone, open the default Camera app and scan the QR code in your terminal. If you are on Android, open the Expo Go app and scan the QR code directly from there.
Voila! You should see your app load.
Now, let's write some code. In modern Expo projects, navigation and screens are handled by files inside the app directory.
Open app/index.tsx (or app/index.js). This is your home screen. Replace the contents with this standard "Hello World" boilerplate:
import { StyleSheet, Text, View } from 'react-native';
export default function HomeScreen() {
return (
<View style={styles.container}>
<Text style={styles.title}>Hello World! 🌍</Text>
<Text style={styles.subtitle}>My first Expo app is alive.</Text>
</View>
);
}
// React Native uses StyleSheet instead of traditional web CSS
const styles = StyleSheet.create({
container: {
flex: 1, // Takes up the whole screen
backgroundColor: '#1E1E1E',
alignItems: 'center',
justifyContent: 'center',
},
title: {
fontSize: 32,
fontWeight: 'bold',
color: '#00D8FF',
},
subtitle: {
fontSize: 16,
color: '#FFFFFF',
marginTop: 10,
}
});Hit save. Because of Hot Module Replacement (HMR), the app on your phone will update almost instantly. You didn't compile any native code; you just sent new JavaScript instructions over the air.
4. Expo Go vs. Development Builds: Knowing Your Tools
Definition:
- Expo Go is a pre-compiled native application available on public app stores that dynamically runs your JavaScript.
- Development Builds are custom, self-compiled native applications that include your specific configurations and third-party native libraries, powered by the
expo-dev-clientpackage.
The Problem:
Expo Go is incredible for starting out. However, Expo Go has a fixed, unchangeable set of native libraries baked into it.
What happens when your client says, "We need to integrate Stripe for payments, use Bluetooth to connect to a smart watch, and add a custom background-location tracking SDK"?
None of those specific native modules exist inside the standard Expo Go app. If you try to install them via npm and run your app, it will crash with an intimidating red screen screaming that a "Native Module is null".
The Solution:
You must transition from Expo Go to a Development Build.
Flow Context:
Imagine you are renting a furnished apartment (Expo Go). It has a bed, a TV, and a microwave. It is perfect for moving in immediately. However, if you want to knock down a wall to install a massive fish tank (a custom native library like Bluetooth), the landlord won't let you. You must move out and build your own custom house (Development Build). The beauty of Expo is that it acts as your automated construction crew to build that custom house for you.
How Industry Handles This:
In the real world, 99% of professional production applications use Development Builds. Expo Go is strictly used for prototyping, learning, and hackathons.
When you hit the limits of Expo Go, you don't panic. You simply generate your own native app using EAS (Expo Application Services).
- You install the development client tool:bash
npx expo install expo-dev-client - You configure your app to build in the cloud using EAS Build.
- EAS compiles a custom version of an app that looks and acts exactly like Expo Go, but it contains your specific Bluetooth and Stripe native code.
- You install this custom
.apk(Android) or.tar.gz(iOS simulator build) on your device. - You run your project utilizing the dev client instead of relying on the default Expo Go mode:bash
npx expo start --dev-client
By relying on Continuous Native Generation (CNG), Expo allows you to keep your hands completely clean of native iOS/Android folders. It generates the native code from your app.json configuration exactly when it needs to build, ensuring you get the raw power of a pure native app without the headache of maintaining Xcode and Android Studio environments.
References & Extra Reading
Challenge
Challenge: Transitioning to a Development Build
You have been developing a React Native application using Expo and testing it successfully on your physical device with the Expo Go app. Now, a new feature requires integrating a third-party native library for Bluetooth functionality, react-native-ble-plx.
Since react-native-ble-plx contains custom native code not included in the standard Expo Go client, you must create a custom Development Build of your app.
Your task is to complete the following shell script. Fill in the placeholders to correctly install the necessary client package and initiate a cloud build for Android using Expo Application Services (EAS).
Expected result
The completed script should correctly identify expo-dev-client as the package for creating development builds and development as the standard profile for EAS Build.
#!/bin/bash
# Step 1: Install the essential package that enables communication
# between your JS code and the custom native build.
npm install "expo-dev-client"
# Step 2: Install the required third-party native library.
npm install react-native-ble-plx
# Step 3: Use the EAS CLI to start a build for the Android platform.
# Specify the correct build profile intended for development purposes.
npx eas build --platform android --profile "development"Explanation:
expo-dev-clientis the library required to create a custom development client. It replaces the Expo Go client and allows your application to load its JavaScript bundle while including custom native modules likereact-native-ble-plx.- The
--profile developmentflag instructs EAS Build to use thedevelopmentprofile from youreas.jsonconfiguration file. This profile is specifically configured to create builds for development, which typically include developer tools and are not optimized for production.