Lesson 10 of 60 – Creating Your First React Native App
17%

Creating Your First React Native App

In this lesson, we will create our first React Native application using Expo. You will learn how to create a project, open it in VS Code, understand the basic files, start the development server and run the application on a device or emulator.

Note: This lesson uses the Expo workflow introduced in the previous lesson. Make sure Node.js and npm are installed before following these steps.

1. What We Will Build

We will create a simple React Native application that displays a welcome message on the mobile screen.

My First App
      ↓
Hello React Native!

The goal is to understand the basic React Native project workflow before building more advanced applications.

2. Check Node.js

Before creating the application, check whether Node.js is installed.

node --version

If a version number is displayed, Node.js is available in the terminal.

3. Check npm

Next, check whether npm is available.

npm --version

npm is used to manage the packages required by the React Native project.

4. Create an Expo Project

Open a terminal and use the Expo project creation command.

npx create-expo-app@latest my-first-app

Here, my-first-app is the name of our project.

5. Project Creation Process

When the command runs, the project creation tool prepares a new React Native application.

npx create-expo-app@latest my-first-app
                    ↓
              Create Project
                    ↓
             React Native App

The generated project contains the files and dependencies needed to start development.

6. Move into the Project Folder

After creating the project, move into the project directory.

cd my-first-app

All project commands should normally be executed from the project directory.

7. Open the Project in VS Code

You can open the project in Visual Studio Code using:

code .

The dot means that VS Code should open the current directory.

8. Install Dependencies

If required, install the project dependencies using:

npm install

npm reads the project configuration and installs the required packages.

9. Start the Development Server

Start the Expo development server with:

npx expo start

The terminal will display information about the running development server and available ways to open the application.

10. Expo Development Server

The development server provides the environment needed to develop and test the application.

It can provide options for opening the application on a physical device, emulator or other supported development environment.

11. Run the App on a Physical Device

You can test a compatible Expo project on a physical mobile device.

For many learning projects, Expo Go can provide a convenient way to open the application during development.

Note: Projects that require native modules or configuration not available in Expo Go may require an Expo development build.

12. Run the App on an Android Emulator

If an Android development environment and emulator are configured, the application can be tested on a virtual Android device.

Android Studio provides the tools required to create and manage Android virtual devices.

13. First Application Screen

The generated project contains starter application code.

You can replace the starter interface with your own React Native components.

import { View, Text } from "react-native";

export default function App() {
    return (
        <View>
            <Text>Hello React Native!</Text>
        </View>
    );
}

14. Import View and Text

The View and Text components can be imported from react-native.

import {
    View,
    Text
} from "react-native";

View can be used as a container, while Text displays text.

15. The App Component

The App component can represent the main component of our application.

export default function App() {
    return (
        <View>
            <Text>Hello React Native!</Text>
        </View>
    );
}

The component returns the interface that should be displayed.

16. Using StyleSheet

We can use StyleSheet to organize the application's styles.

import {
    View,
    Text,
    StyleSheet
} from "react-native";

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center"
    }
});

17. Create a Simple Styled Screen

We can apply the style to our View component.

export default function App() {
    return (
        <View style={styles.container}>
            <Text>Hello React Native!</Text>
        </View>
    );
}

The content will be positioned in the center of the available screen.

18. Add More Text

Multiple Text components can be placed inside the View.

<View style={styles.container}>

    <Text>Welcome to React Native</Text>

    <Text>
        My First Mobile App
    </Text>

</View>

19. Add a Pressable Button

The Pressable component can be used to create an interactive area.

import {
    View,
    Text,
    Pressable
} from "react-native";

<Pressable
    onPress={() => alert("Hello!")}
>
    <Text>Press Me</Text>
</Pressable>

20. Complete First App Example

import {
    View,
    Text,
    Pressable,
    StyleSheet
} from "react-native";

export default function App() {

    function showMessage() {
        alert("Welcome to React Native!");
    }

    return (
        <View style={styles.container}>

            <Text style={styles.title}>
                My First React Native App
            </Text>

            <Text>
                Welcome to Soopro Pathshala
            </Text>

            <Pressable
                style={styles.button}
                onPress={showMessage}
            >

                <Text style={styles.buttonText}>
                    Press Me
                </Text>

            </Pressable>

        </View>
    );
}

const styles = StyleSheet.create({

    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        padding: 20
    },

    title: {
        fontSize: 24,
        fontWeight: "bold",
        marginBottom: 15
    },

    button: {
        marginTop: 20,
        padding: 15,
        borderRadius: 8,
        backgroundColor: "blue"
    },

    buttonText: {
        color: "white",
        fontSize: 16
    }

});

21. Understand the Application Flow

App Component
      ↓
     View
      ↓
 ┌────┴─────────┐
 ↓              ↓
Text         Pressable
                 ↓
              onPress
                 ↓
          JavaScript Function

This simple application already demonstrates components, styling, events and JavaScript functions.

22. Save Your Changes

After changing your code, save the file in VS Code.

When Fast Refresh is available, many changes can appear automatically in the running application.

This allows you to quickly test changes while developing.

23. Test the Button

Press the button displayed in the application.

Press Me
   ↓
onPress
   ↓
showMessage()
   ↓
Alert Message

This demonstrates how user interaction can trigger JavaScript logic.

24. Understanding the Project Folder

A newly created Expo project contains configuration files, source files, dependencies and assets.

my-first-app/
├── app/
├── assets/
├── node_modules/
├── package.json
├── app.json
└── ...

The exact files depend on the project template and Expo version.

25. package.json Scripts

The package.json file can contain scripts used to run the project.

{
    "scripts": {
        "start": "expo start"
    }
}

The exact scripts depend on the project template.

26. Common Error: Command Not Found

If the terminal reports that a command is not recognized, first check that Node.js is installed correctly.

node --version
npm --version

Also make sure you are using a new terminal after installing Node.js.

27. Common Error: Wrong Project Folder

React Native commands should normally be run from the project folder.

cd my-first-app

npx expo start

If the terminal is in another directory, the expected project files may not be found.

28. Common Error: Application Does Not Update

If your changes do not appear immediately:

  • Save the file.
  • Check the terminal for errors.
  • Check the application console.
  • Restart the development server if necessary.
  • Verify that you edited the correct project file.

29. First App Development Workflow

Check Node.js
      ↓
Create Expo Project
      ↓
Open Project
      ↓
Install Dependencies
      ↓
Start Expo
      ↓
Create Components
      ↓
Add Styles
      ↓
Add Events
      ↓
Test App
      ↓
Fix Errors

30. Complete First App Code

Here is a simple complete application that combines the main concepts learned in this lesson:

import {
    View,
    Text,
    Pressable,
    StyleSheet
} from "react-native";

export default function App() {

    const handlePress = () => {
        alert("Button Pressed!");
    };

    return (
        <View style={styles.container}>

            <Text style={styles.title}>
                Welcome to React Native
            </Text>

            <Text style={styles.subtitle}>
                My First Mobile Application
            </Text>

            <Pressable
                style={styles.button}
                onPress={handlePress}
            >

                <Text style={styles.buttonText}>
                    Click Me
                </Text>

            </Pressable>

        </View>
    );
}

const styles = StyleSheet.create({

    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        padding: 20
    },

    title: {
        fontSize: 26,
        fontWeight: "bold",
        textAlign: "center"
    },

    subtitle: {
        marginTop: 10,
        fontSize: 16,
        textAlign: "center"
    },

    button: {
        marginTop: 25,
        paddingVertical: 12,
        paddingHorizontal: 25,
        borderRadius: 8,
        backgroundColor: "blue"
    },

    buttonText: {
        color: "white",
        fontSize: 16,
        fontWeight: "bold"
    }

});

You have now created a basic React Native application with a screen, text, styling and an interactive button.

📌 Key Points

  • A React Native project can be created using Expo.
  • npx create-expo-app@latest can create an Expo project.
  • cd is used to enter the project directory.
  • npm install installs project dependencies.
  • npx expo start starts the Expo development server.
  • View is commonly used as a container.
  • Text is used to display text.
  • Pressable can be used for interactive elements.
  • StyleSheet helps organize component styles.
  • React Native applications can be tested on physical devices and emulators.

🧠 Quick Quiz

Question: Which command is used to start the Expo development server?