codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
⚛️

React.js

53 / 61 topics
52Introduction to React Native53Building Your First App with React Native54State Management in React Native55Navigation in React Native56Performance Tips for React Native Apps
Tutorials/React.js/Building Your First App with React Native
⚛️React.js

Building Your First App with React Native

Updated 2026-04-20
4 min read

Introduction

React Native is a powerful framework that allows you to build cross-platform mobile applications using JavaScript and React. It enables you to write code once and deploy it on both iOS and Android platforms, making it an excellent choice for developers looking to maximize their productivity.

In this tutorial, we'll walk through the process of building your first app with React Native. We'll cover setting up your development environment, creating a new project, navigating the basic structure, and implementing some fundamental components.

Prerequisites

Before you start, ensure that you have the following installed:

  • Node.js: Make sure you have Node.js version 14 or higher installed. You can download it from nodejs.org.
  • npm (Node Package Manager): This usually comes with Node.js installation.
  • Java Development Kit (JDK): Required for Android development. Download it from Oracle's website or use OpenJDK.
  • Android Studio: Install the latest version of Android Studio, which includes the Android SDK and emulator.

Setting Up Your Development Environment

1. Install React Native CLI

Open your terminal and run the following command to install the React Native CLI globally:

npm install -g react-native-cli

2. Configure Android Environment Variables

You need to set up some environment variables for Android development. Follow these steps:

  • ANDROID_HOME: Set this variable to the path where Android SDK is installed.
  • PATH: Add the platform-tools and tools directories of your Android SDK to the PATH.

For example, on a Unix-based system (Linux or macOS), you can add the following lines to your .bashrc or .zshrc file:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

After adding these lines, reload your shell configuration:

source ~/.bashrc  # or source ~/.zshrc

3. Install Watchman

Watchman is a tool by Facebook that helps detect file changes in the filesystem. It's required for React Native development.

Install it using Homebrew (for macOS):

brew install watchman

Or, download and install it from watchman.io.

Creating a New React Native Project

Now that your environment is set up, let's create a new React Native project.

1. Create the Project

Run the following command to create a new React Native project:

npx react-native init MyFirstApp

This will create a new directory named MyFirstApp with all the necessary files and dependencies.

2. Navigate to the Project Directory

Change into your project directory:

cd MyFirstApp

Running Your App on an Emulator or Device

Before we start coding, let's run our app to ensure everything is set up correctly.

1. Start Metro Bundler

Metro Bundler is the JavaScript bundler used by React Native. Start it with:

npx react-native start

2. Run on Android Emulator

If you have an Android emulator running, you can run your app on it:

npx react-native run-android

3. Run on iOS Simulator (macOS only)

For macOS users, you can also run the app on an iOS simulator:

npx react-native run-ios

Exploring the Project Structure

Let's take a look at the basic structure of a React Native project.

  • android/: Contains all Android-specific files.
  • ios/: Contains all iOS-specific files.
  • node_modules/: Contains third-party libraries and dependencies.
  • App.js: The main entry point of your app.
  • index.js: Entry file for the JavaScript code.
  • package.json: Contains project metadata and dependencies.

Building Your First App

Now, let's build a simple app that displays a welcome message and a button. When the button is pressed, it will display an alert.

1. Modify App.js

Open App.js in your favorite code editor and replace its content with the following:

import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';

const App = () => {
  const showAlert = () => {
    alert('Hello, React Native!');
  };

  return (
    <View style={styles.container}>
      <Text style={styles.welcome}>Welcome to My First App!</Text>
      <Button title="Press Me" onPress={showAlert} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

export default App;

2. Explanation of the Code

  • Import Statements: We import necessary components from react-native, such as Text, View, and Button.
  • App Component: This is a functional component that returns JSX, which describes what should be rendered on the screen.
  • showAlert Function: This function displays an alert when the button is pressed.
  • Stylesheet: We define styles using StyleSheet.create to style our components.

3. Run Your App

Save your changes and run your app again using the same commands as before:

npx react-native run-android  # For Android
npx react-native run-ios      # For iOS (macOS only)

You should see a screen with a welcome message and a button. Pressing the button will show an alert.

Best Practices

  • Use Functional Components: React Native encourages the use of functional components with hooks for better performance and readability.
  • Keep Components Reusable: Break down your UI into smaller, reusable components to maintain clean code.
  • Manage State Efficiently: Use useState and useReducer hooks for state management in functional components.
  • Use Stylesheets: Define styles using StyleSheet.create for consistency and performance.

Conclusion

Congratulations! You've successfully built your first app with React Native. This tutorial covered setting up the development environment, creating a project, running the app on an emulator or device, and building a simple UI component. From here, you can explore more advanced features of React Native and start developing complex cross-platform applications.

Remember to refer to the official React Native documentation for more detailed information and best practices. Happy coding!


PreviousIntroduction to React NativeNext State Management in React Native

Recommended Gear

Introduction to React NativeState Management in React Native