Skip to main content

Setting Up Development Environment

1. Installing React Native CLI

Step Description Command Notes
1 Install Node.js (v18 or later) node --version Required for React Native development
2 Install React Native CLI globally npm install -g react-native-cli Alternative: use npx react-native for local CLI
3 Verify installation react-native --version Should display React Native CLI version

Example: Create a new React Native project

react-native init MyProject
cd MyProject
react-native run-ios
Note: For newer projects, consider using npx react-native init instead of installing the CLI globally.

2. Setting Up Android Studio

Example: Install Android Studio

# Download and install Android Studio
# For macOS
brew install --cask android-studio

# For Windows/Linux
# Download from https://developer.android.com/studio
Step Description Notes
1. Download Android Studio Visit the official Android Studio download page Choose the appropriate version for your OS
2. Install Android Studio Run the installer and follow the setup wizard Ensure all components are selected for React Native development
3. Configure SDK Install required Android SDKs and system images Use the SDK Manager to install latest API level
Note: Make sure to install the Android SDK and NDK as part of the setup process.
Warning: Ensure that your system meets the minimum requirements for Android Studio.

Summary of Setup Steps

  • Download Android Studio from the official website
  • Install Android Studio with default settings
  • Configure SDK and system images
  • Set up environment variables (e.g., ANDROID_HOME)

3. Setting Up Xcode

Note: Xcode is required for iOS development in React Native. Ensure you have macOS 10.15 or later.
Step Description Action
1 Download Xcode Go to App Store and install Xcode.
2 Install Command Line Tools Open Terminal and run: xcode-select --install
3 Accept License Agreement Open Xcode and accept the license agreement.

Example: Verify Installation

xcode-select -p

Key Points

  • Xcode is required for iOS builds and simulators.
  • Command Line Tools must be installed separately.
  • Ensure Xcode version is compatible with your React Native version.

4. Configuring Metro Bundler

Configuration Option Description Default Value Notes
metro.config.js Entry point for Metro configuration metro.config.js Located in project root
projectRoot Root directory of the project process.cwd() Used to resolve dependencies
resetCache Force Metro to reset its cache false Useful during development when dependencies change
maxWorkers Number of workers to use for building bundles Math.max(1, os.cpus().length - 1) Can be adjusted for performance tuning
watchFolders Additional directories to watch for file changes [] Useful when linking local packages
transformer Options for the transformer module {} Allows customization of how files are transformed

Example: Basic metro.config.js

module.exports = {
  projectRoot: __dirname,
  resetCache: false,
  maxWorkers: 2,
  watchFolders: [],
  transformer: {
    babelTransformerPath: require.resolve('metro-react-native-babel-transformer'),
  },
};
Note: The metro.config.js file is processed by Node.js, so it must be valid JavaScript.
Warning: Modifying the maxWorkers setting can impact build performance. Setting it too high may cause memory issues.

Key Configuration Points

  • projectRoot: Ensures correct resolution of dependencies.
  • resetCache: Useful for clearing outdated cache entries during development.
  • maxWorkers: Adjust based on system resources to optimize build times.
  • watchFolders: Helps in linking local packages or monorepos.
  • transformer: Allows customization of the transformation process for specific file types.

5. Setting Up TypeScript

Example: Project Setup with TypeScript

npm install -g @react-native-community/cli
npx react-native init MyTSApp --template react-native-template-typescript
Feature Description Notes
TypeScript Support Officially supported in React Native Enables type checking and better IDE support
File Extensions .tsx and .ts Use .tsx for components with JSX
TypeScript Config tsconfig.json Configures compiler options and paths
Note: Ensure your editor supports TypeScript for best experience.

Example: Basic Component with Types

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

interface Props {
  title: string;
  count: number;
}

const MyComponent: React.FC<Props> = ({ title, count }) => {
  return (
    <View>
      <Text>{title}: {count}</Text>
    </View>
  );
};

export default MyComponent;

6. Configuring ESLint and Prettier

Example: ESLint Configuration

{
  "extends": [
    "@react-native-community"
  ],
  "rules": {
    "react-native/no-inline-styles": "warn",
    "no-unused-vars": "error"
  }
}
Rule Description Default Severity
react-native/no-inline-styles Disallows inline styles in components warn
no-unused-vars Reports unused variables error

Example: Prettier Configuration

{
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5"
}
Option Description Values
semi Whether to add semicolons true, false
singleQuote Whether to use single quotes true, false
trailingComma Whether to add trailing commas "es5", "none"
Note: ESLint and Prettier configurations should be placed in .eslintrc.js and .prettierrc respectively.

7. Setting Up Environment Variables

Variable Name Value Description
REACT_NATIVE_DEBUG true or false Enables or disables debugging mode in React Native
NODE_ENV development, production Controls the environment for the app build
CI true Indicates if the build is running in a CI environment

Example: Setting Environment Variables in .env File

REACT_NATIVE_DEBUG=true
NODE_ENV=development
CI=false
Note: Environment variables in React Native are typically managed using the .env file and loaded via libraries like react-native-config.

8. Initializing New Project

Example: Create a new React Native project

npx react-native init MyProject
Command Description Notes
npx react-native init <projectName> Creates a new React Native project Uses the latest stable version of React Native
npx react-native init <projectName> --template react-native-template-typescript Creates a new React Native project with TypeScript support Uses the latest stable version of React Native and TypeScript template
Note: Ensure Node.js (v16 or higher) and Watchman are installed before initializing a new project.

9. Configuring Watchman

Example: Install and Configure Watchman

# On macOS
brew install watchman

# On Linux
sudo apt update
sudo apt install watchman

# On Windows (via Chocolatey)
choco install watchman
Configuration Description Default Value Notes
watchman.max_files Maximum number of files Watchman will watch 100000 Adjust based on project size
watchman.recursion_depth Maximum depth to recurse into directories 10 Higher values may impact performance
watchman.ignore_dirs Directories to exclude from watching [".git", "node_modules"] Customize based on project structure
Note: Watchman is essential for React Native's file change detection. It significantly improves performance over the default file system watchers.
Warning: On Linux systems, ensure the inotify limits are sufficient to handle large projects. Adjust /proc/sys/fs/inotify/max_user_watches if needed.

10. Using React Native Doctor

Example: Run React Native Doctor

react-native doctor
Check Description Status
Node.js version Checks if Node.js is installed and compatible NEW 18+
React Native CLI Verifies React Native CLI is installed Required
Xcode Checks for Xcode on macOS Required for iOS builds
Android Studio Verifies Android Studio and SDKs Required for Android builds
Watchman Ensures Watchman is installed (macOS) Recommended
Note: The React Native Doctor tool helps diagnose and fix common setup issues in your development environment.
Warning: Make sure to run react-native doctor from the root of your project directory.

11. Setting Up Flipper

Example: Install Flipper

# Download Flipper from the official website or GitHub
# For macOS:
brew install flipper

# For Windows/Linux:
# Download the installer from https://fbflipper.com/docs/getting-started
Step Description Notes
Download Flipper https://fbflipper.com/docs/getting-started Official Flipper download page
Install via Homebrew (macOS) brew install flipper Simple installation method for macOS users
Manual Installation (Windows/Linux) Download installer from Flipper website Requires manual setup and configuration
Note: Flipper is a desktop application that helps developers debug and inspect React Native apps. It provides tools for network inspection, state management, and more.
Warning: Ensure that Flipper is compatible with your React Native version to avoid any debugging issues.

12. Configuring Path Aliases

Path aliases help simplify import paths in React Native projects, making code more readable and maintainable.

Alias Target Path Description
src ./src Root directory of source files
components ./src/components Directory for reusable UI components
utils ./src/utils Directory for utility functions and helpers
assets ./src/assets Directory for static assets like images and icons

Example: Setting up path aliases in tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "src": ["./src"],
      "components": ["./src/components"],
      "utils": ["./src/utils"],
      "assets": ["./src/assets"]
    }
  }
}

Example: Using path aliases in code

import Button from "components/Button";
import { formatDate } from "utils/dateUtils";
import logo from "assets/images/logo.png";

Was this article helpful?