This tutorial outlines the foundational knowledge and skills you should ideally have before diving deep into React Native development.

Prerequisites

Understanding Basic Requirements

Before starting with React Native, several basic requirements will set the stage for a productive learning experience:

JavaScript Knowledge

  • At the core of React Native development is JavaScript, the scripting language used to write your app’s logic and interface. A solid understanding of JavaScript, including ES6 features like arrow functions, classes, destructuring, and promises, is important.
  • If you’re new to JavaScript or need a refresher, consider going through online tutorials or courses focused on modern JavaScript.

Basic Programming Concepts

  • Familiarity with fundamental programming concepts such as variables, control flow (if statements, loops), functions, and data structures (arrays, objects) is essential.
  • Understanding asynchronous programming concepts, including callbacks, promises, and async/await, is particularly beneficial given the nature of mobile app development.

Development Environment

  • Setting up your development environment is the first technical step. This includes installing js (which comes with npm) and setting up the appropriate SDKs depending on your target platform (e.g., Android Studio for Android development, Xcode for iOS).

Version Control with Git

  • Knowledge of version control, particularly Git, is invaluable for managing your code, collaborating with others, and integrating with the broader ecosystem of React Native libraries and tools.

Familiarity with React

While not strictly required, having a background in React (the library that React Native is based on) can significantly smooth your learning curve:

React Fundamentals

  • Understanding React’s core principles, such as components, state, and props, will help you understand React Native’s development model more quickly. React Native uses the same design philosophy but applies it to mobile app development.
  • Familiarity with the component lifecycle, hooks (for functional components), and context API for state management within React apps is beneficial.

JSX Syntax

  • JSX is a syntax extension for JavaScript that allows you to write UI components in a way that resembles HTML. Knowing JSX will enable you to define the layout and structure of your mobile app’s interface seamlessly.

Single Page Applications (SPA)

  • Experience with building SPAs using React will give you insights into component-based architecture and state management’s importance, concepts directly applicable to React Native apps.

Ecosystem and Tools

  • Familiarity with the React ecosystem, including tools like Webpack, Babel, and various debugging techniques, will be advantageous as similar tools and processes are used in React Native development.

System Requirements

Hardware and Software Needs

Hardware Requirements

  • Processor: A modern processor (i.e., Intel i5/i7/i9 or AMD Ryzen 5/7/9) will ensure the smooth performance of your development tools and emulators. React Native development is CPU-intensive, especially when using emulators or simulators.
  • Memory (RAM): A minimum of 8GB RAM is recommended, but 16GB or more is preferable for running emulators and your development tools simultaneously without slowdowns.
  • Storage: SSD (Solid State Drive) with at least 20GB of free space. SSDs offer faster read/write speeds compared to HDDs, which can significantly speed up build times and application loading times.
  • Operating System:Windows 10 or later, macOS Catalina (10.15) or later, or a recent version of Linux (Ubuntu, Fedora, or similar). The operating system should be 64-bit.

Software Requirements

  • js and npm (Node Package Manager): React Native relies on Node.js to run the JavaScript code and npm to manage project dependencies. The latest LTS (Long-Term Support) version of Node.js is recommended.
  • Watchman (optional for macOS/Linux):Watchman is a tool by Facebook for watching changes in the filesystem. It’s useful for improving the performance of live reloading and hot reloading features in React Native.
  • Java Development Kit (JDK):JDK version 8 or newer is required to develop React Native apps for Android.
  • Android Studio: For Android app development, Android Studio provides the Android SDK, emulator, and various tools needed to build and test your app.
  • Xcode (macOS only): For iOS app development, Xcode is necessary. It includes the iOS SDK, simulator, and other tools required for iOS development. Xcode is available only on macOS.

Hardware Requirements

Setting up your development environment involves installing the required software and configuring your system to develop and test React Native applications:

 1. Install Node.js and npm:

    • Download and install Node.js from https://nodejs.org/. npm is included with Node.js.
    • Verify the installation by running node -v and npm -v in your terminal or command prompt.

2. Install the Java Development Kit (JDK):

    • Download and install the JDK from Oracle’s website or use OpenJDK.
    • Set up the JAVA_HOME environment variable to point to your JDK installation path.

3. Android Studio:

    • Download and install Android Studio from https://developer.android.com/studio.
    • During installation, make sure to install the Android SDK, Android SDK Platform, and Android Virtual Device.
    • Configure the ANDROID_HOME environment variable to point to your Android SDK location.

4. Xcode (macOS only):

    • Install Xcode from the Mac App Store.
    • Ensure you also install the Xcode Command Line Tools by running xcode-select –install in the terminal.

5. Watchman (Optional for macOS/Linux):

After setting up these components, your system will be ready for React Native development. This setup allows you to start building and testing apps on both Android and iOS platforms.

Installation of Node.js, npm, and either Expo CLI or React Native CLI

Installing Node.js and npm

1. Download Node.js:

    • Visit the js website and download the installer for your operating system. The LTS (Long-Term Support) version is recommended for its stability and extended support.

2. Install Node.js and npm:

    • Run the downloaded installer, following the prompts to install js and npm. The installer includes npm by default.

3. Verify Installation:

    • Open a terminal or command prompt and enter node -v and npm -v to verify the successful installation of Node.js and npm, respectively. You should see the version numbers of each program.

Choosing Between Expo CLI and React Native CLI

Expo CLI

  • Expo is a framework and a platform for universal React applications. It’s an excellent choice for beginners due to its simplified setup process and managed workflow, which abstracts much of the complexity of configuring native code. Expo allows you to build, deploy, and quickly iterate on iOS, Android, and web apps from the same JavaScript/TypeScript codebase.
  • Recommended for those new to mobile development or who wish to prototype applications rapidly without dealing with native code.

React Native CLI

  • The React Native CLI offers more control over the build and configuration process, making it suitable for projects that require custom native code integration. With the React Native CLI, you’re responsible for setting up your development environment, including Android Studio and Xcode configurations.
  • Choose the React Native CLI if you need to develop a more complex app that requires direct access to native APIs or if you plan to include custom native modules.

Installation Process

For Expo CLI

1. Install Expo CLI:

With Node.js and npm installed, run the following command to install Expo CLI globally:

npm install -g expo-cli

2. Create a New Expo Project:

To create a new Expo project, run:

expo initMyExpoProject

Follow the prompts to choose a template and configure your project.

For Expo CLI

1. Install React Native CLI

Install the React Native CLI globally using npm:

npm install -g react-native-cli

2. Create a New React Native Project

Once the CLI is installed, initiate a new project with:

npx react-native initMyReactNativeProject

This command creates a new React Native project with all necessary configurations.

By following these steps, you’ll have the core tools installed and be ready to start developing with either Expo or React Native, depending on your project’s needs and your personal or organizational preferences.

Creating and Running a New React Native Project

Initializing a New Project

Using Expo CLI

If you’ve chosen Expo CLI for its simplicity and managed workflow, initializing a new project is straightforward:

1. Create Expo Project:

Open a terminal or command prompt and run:

expo initMyExpoProject

Replace MyExpoProject with your desired project name. You will be prompted to choose a template; “blank” is a good starting point for beginners.

2. Navigate to Your Project Directory:

cd MyExpoProject

Using React Native CLI

For those who prefer more control and direct access to native code via React Native CLI:

1. Create React Native Project:

In your terminal or command prompt, execute:

npx react-native initMyReactNativeProject

This command creates a new React Native project. Replace MyReactNativeProject with your project name.

2. Navigate to Your Project Directory:

cd MyReactNativeProject

Running the Project

With Expo

1. Start the Project

Inside your project directory, start the Expo project by running:

expo start

2. Open Your App

Expo starts a development server and opens a web interface in your default browser. You can scan the QR code with the Expo Go app on your iOS or Android device to see your app live. Alternatively, use Android Emulator or iOS Simulator from the web interface.

With React Native CLI

1. Running on iOS (Only available on macOS)

npx react-native run-ios

This command builds your app and starts it on the iOS Simulator.

2. Running on Android:

Make sure you have an Android emulator running or a device connected, and then execute:

npx react-native run-android

Your app will be built and launched on the Android device or emulator.

First Look at a React Native App

Upon successfully running your project, you’ll see the default React Native app screen. This screen typically displays a welcome message such as “Welcome to React” and instructions for editing the App.js file to get started. This initial app serves as a canvas for your development, where you can begin to implement your app’s features and UI components.

Exploring App.js

The App.js file in your project directory is the entry point of your app. It’s where you define your app’s layout and behavior using React components. Try modifying the text or styles in App.js and save the file. You’ll see the changes reflected immediately in your running app due to the hot reloading feature.

Understanding the Project Structure

Spend some time exploring the files and folders in your project directory. For Expo projects, most of your work will be within the App.js file and adding new components or assets.

For React Native CLI projects, you’ll find additional directories for iOS and Android native code, which you can modify as your app requires direct native functionalities.

Congratulations! You’ve now set the foundation for your React Native development journey. From here, you can start building out your app’s components, logic, and styling, experimenting with React Native’s extensive capabilities to create compelling mobile applications.

Overview of Project Structure

Understanding the File System

When you create a new React Native project through Expo CLI or React Native CLI, the generated project comes with a predefined structure.

Here’s a breakdown of the essential files and directories:

  • node_modules/: This directory contains all the project dependencies installed via npm or yarn. It’s automatically managed by your package manager and typically not modified directly.
  • ios/ and android/: These directories exist in React Native CLI projects and contain the native code for iOS and Android, respectively. You can find project files, Gradle configurations (Android), and Xcode project files (iOS) here. These folders are not present in projects created with Expo CLI unless you’ve ejected the project.
  • js: This is the entry point of your React Native app. It’s a JavaScript file where your app’s initial component is defined. Modifying this file changes the content of your app.
  • json: This file holds metadata relevant to the project and manages project dependencies. It includes scripts for running the app and lists all the npm packages your project depends on.
  • config.js: Configuration file for Babel, a tool that compiles your JavaScript code down to a version that can run on older devices. It ensures compatibility and optimal performance.
  • js: The main JavaScript entry point for running the React Native application. It registers the app root component with AppRegistry.

Key Components

  • Components: React Native uses components as the building blocks of the app’s UI. Components are defined in JavaScript files and can be either class-based or functional. They’re reusable and can be nested within each other.
  • Assets: Images, fonts, and other static files are stored in the assets You can reference these in your app to add logos, icons, and other media.
  • Navigation: If your app has multiple screens, you’ll use a navigation library (e.g., React Navigation) to manage screen transitions. The configuration for your navigation structure is typically found in separate JavaScript files.

Customizing the Project

  • Adding Dependencies: You can install additional packages using npm or yarn to add new functionality. For example, npm install react-navigation installs the navigation library.
  • Environment Configuration: You might need to configure environment variables or settings specific to iOS or Android. This can involve editing files within the ios/ and android/ directories for native configurations.
  • Styling: React Native uses a styling system similar to CSS but with a JavaScript syntax. Styles are defined within the same file as your components or in separate files for larger projects.
  • State Management: For complex applications, you might introduce state management libraries like Redux or Context API to manage data across components.