No history yet

Introduction to React Native

Build for Mobile with JavaScript

If you know how to build a website with React, you're already halfway to building a mobile app. That's the core idea behind React Native. It’s a framework that lets you use your JavaScript and React skills to create apps for both iOS and Android from a single codebase.

Lesson image

Think of it like a translator. You write your app's logic and design once, using familiar tools. React Native then translates that code into the native user interface elements for each platform. An iOS user gets the standard iOS buttons and menus, while an Android user gets the Android equivalents. The result is an app that looks and feels truly native, not like a website squeezed onto a phone.

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces.

This approach saves a huge amount of time and effort. Instead of maintaining two separate projects—one in Swift or Objective-C for iOS, another in Kotlin or Java for Android—you manage one. This means faster development, easier updates, and a more consistent experience for your users across devices.

Setting Up Your Workspace

Getting started with React Native is surprisingly straightforward, especially with a tool called Expo. Expo is a set of tools and services built around React Native that simplifies the development process. It handles much of the complex configuration for you, so you can focus on building your app.

We'll use the Expo Go workflow. It's the fastest way to get up and running, allowing you to see your app on a physical device in minutes without installing developer tools like Xcode or Android Studio.

First, you'll need Node.js on your computer. If you don't have it, you can download it from the official website. With Node.js installed, you can use its package manager, npm, to install the Expo command line interface (CLI). Open your terminal and run this command:

npm install -g expo-cli

Once that's done, you can create a new project. Navigate to the directory where you want to store your app and run:

npx create-expo-app MyFirstApp

This command creates a new folder named MyFirstApp with all the necessary files. Finally, install the Expo Go app on your iOS or Android phone from the App Store or Play Store. This app will let you run your project on your device by simply scanning a QR code.

Core Building Blocks

If you've used React for the web, you're used to working with HTML tags like <div>, <p>, and <img>. React Native provides its own set of core components that serve similar purposes but are designed for mobile interfaces. Instead of writing for a browser, you're writing for a native mobile environment.

Web (HTML)React Native ComponentPurpose
<div><View>A container for other elements, used for layout.
<p>, <h1><Text>For displaying text. All text must be inside a <Text> component.
<img><Image>For displaying images.
<input><TextInput>A component for user text input.
<button><Button>A basic, platform-specific button.
<div> (scrollable)<ScrollView>A generic scrolling container.

These components map directly to the native UI widgets on iOS and Android. A <Button> will render as a standard iOS button on an iPhone and a standard Android button on a Pixel. This is how React Native achieves its native look and feel.

Run Your First App

Let's bring it all together. Navigate into your new project directory in the terminal:

cd MyFirstApp

Now, start the development server:

npx expo start

Your terminal will display a QR code. Open the Expo Go app on your phone and scan it. The app will bundle the JavaScript code and send it to your phone, where you'll see your first React Native application running live.

Try opening the App.js file in your project. Find the <Text> component and change its content. As soon as you save the file, the app on your phone will update automatically. This feature, called Fast Refresh, makes development incredibly quick and interactive.

Quiz Questions 1/5

What is the primary advantage of using React Native for mobile app development?

Quiz Questions 2/5

True or False: React Native renders standard HTML tags like <div> and <p> to create the user interface on mobile devices.

You now have the foundational knowledge to start building with React Native. You've learned what it is, how to set up your environment with Expo, and how to run a basic application. The next step is to start combining these components to build more complex and interesting user interfaces.