Skip to main content

Installing React

This guide walks you through setting up React in your project. Whether you’re starting a new project or adding React to an existing one, you’ll find the instructions you need here.

Requirements

Before you begin, make sure you have the following installed on your system:
  • Node.js - Version 0.10.0 or higher (though we recommend the latest LTS version for best experience)
  • npm - Usually comes with Node.js, or you can use yarn/pnpm as alternatives
  • A code editor (we recommend VS Code with the ES7+ React snippets extension)
To check your Node.js version, run node --version in your terminal. To check npm, run npm --version.

Installation Methods

You can install React in several ways depending on your project needs: Install React and React DOM using your preferred package manager:
This installs:
  • react (v19.3.0) - The core React library for defining components
  • react-dom - The React renderer for web applications
The react package contains only the functionality necessary to define React components. You need react-dom to render components in the browser.

Method 2: Using a CDN

For quick prototypes or learning, you can include React directly via CDN without any build tools:
CDN builds are great for learning and prototyping, but use the npm version for production applications. The CDN approach doesn’t support JSX syntax without additional transpilation.

Method 3: Using Create React App

Create React App sets up a modern React development environment with zero configuration:
This creates a new directory with a complete React project structure, including:
  • A development server with Fast Refresh
  • A build script that bundles your app for production
  • ESLint configuration for catching common mistakes
  • Jest setup for testing

Method 4: Using Vite (Fast Alternative)

Vite offers a faster development experience with near-instant server start:

Creating Your First React App

1

Create a new directory

Open your terminal and create a new project directory:
2

Initialize your project

Create a package.json file:
3

Install React

Install React and React DOM:
4

Install a bundler

For development, you’ll need a bundler. Install Vite for a fast experience:
5

Create your project structure

Create the following files:
6

Configure Vite

Add this to vite.config.js:
7

Create your HTML file

Add this to index.html:
8

Create your entry point

Add this to src/main.jsx:
9

Create your first component

Add this to src/App.jsx:
10

Add scripts to package.json

Update your package.json to include:
11

Start the development server

Run your application:
Open your browser to http://localhost:5173 to see your app running!

Verifying Your Installation

After installation, verify everything works by creating a simple test component:
If you see the message and the button responds to clicks, your React installation is working correctly!

Using React with TypeScript

For TypeScript support, install the type definitions:
Then rename your files from .jsx to .tsx and enjoy full type safety:

Additional Tools

Consider installing these tools for a better development experience:
  • React DevTools - Browser extension for debugging React applications
  • ESLint - Catch errors and enforce code style
  • Prettier - Code formatter for consistent style
  • React Testing Library - Test your React components

Production Build

When you’re ready to deploy your application, React provides optimized production builds that:
  • Remove development-only code and warnings
  • Minify your code for smaller bundle sizes
  • Enable production optimizations
Always use the production build when deploying. The development version includes extra warnings and helpful error messages, but these make the bundle larger and slower.
Build for production:
This creates an optimized production build in the dist or build directory, ready for deployment.

Troubleshooting

Module not found errors: Make sure you’ve installed all dependencies with npm install. React hooks not working: Ensure you’re using React 16.8.0 or higher. Check with npm list react. Different React versions: Having multiple versions of React can cause issues. Run npm list react to check for duplicates. JSX not recognized: Make sure your build tool is configured to handle JSX. With Vite, ensure you’re using .jsx or .tsx file extensions.

Next Steps

Now that you have React installed, you’re ready to start building!

Quickstart Tutorial

Build your first React app with a hands-on tutorial

Learn Key Concepts

Understand components, props, state, and hooks