Setting up a React project

Topic 2 of 4 in Getting started7 min readIntermediateFree course

Overview

To write React you need a few tools: something to turn JSX into JavaScript, a development server that reloads instantly when you save, and a way to bundle everything for production. Vite (French for “fast”, pronounced veet) does all three, and it’s the standard way to start a React app that doesn’t need a full framework.

Prerequisites

  1. Node.js 22 or later — check with node --version. Download the LTS version from nodejs.org if needed. Vite 8 requires Node 20.19+ or 22.12+.
  2. A code editor — VS Code is the most common choice. Useful extensions: ESLint or Oxc for linting, Prettier for formatting.
  3. A modern browser — Chrome, Edge or Firefox, with React Developer Tools installed (more on that below).

Create the project

Terminal
npm create vite@latest course-catalog -- --template react
cd course-catalog
npm install
npm run dev
  • npm create vite@latest downloads Vite’s project generator.
  • --template react picks the React + JavaScript template. Use react-ts for TypeScript (see React with TypeScript).
  • npm install downloads React, Vite and the other dependencies.
  • npm run dev starts the dev server. Open the URL it prints — usually http://localhost:5173.

You should see a starter page with a counter button. Open src/App.jsx, change some text and save: the browser updates in milliseconds, without losing the counter’s value. That’s Hot Module Replacement (HMR).

What’s in the project

The project folder contains index.html, package.json, vite.config.js, a public folder and a src folder with main.jsx, App.jsx and index.css. The browser loads index.html, which contains a div with id root and loads main.jsx; main.jsx calls createRoot on that element and renders App. The Vite dev server serves the files, transforms JSX and hot-reloads on save.

index.html

HTML
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>

The only HTML file in the app. React will fill the empty <div id="root">. Unlike older tools, Vite treats index.html as the entry point and lives at the project root, not in public/.

src/main.jsx

JSX
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.jsx';

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <App />
  </StrictMode>,
);

This is where React starts:

  • createRoot(element) creates a React root — React takes control of everything inside that DOM element.
  • .render(<App />) renders your top-level component into it.
  • import './index.css' — Vite lets you import CSS files from JavaScript; they’re added to the page.

src/App.jsx

Your top-level component. Everything else in your app will be rendered from here.

package.json

JSON
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "oxlint",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^19.3.1",
    "react-dom": "^19.3.1"
  }
}

Two packages make up React on the web: react (components, hooks, the core) and react-dom (rendering into the browser’s DOM).

Other files

  • vite.config.js — Vite’s configuration; the @vitejs/plugin-react plugin adds JSX support and Fast Refresh.
  • public/ — files copied as-is (favicons, robots.txt). Reference them with absolute paths like /favicon.svg.
  • src/assets/ — images you import from code; Vite optimises and fingerprints them.

StrictMode

<StrictMode> doesn’t render anything visible. In development only, it helps you find bugs by:

  • rendering components twice to expose impure rendering code,
  • running effects setup → cleanup → setup to expose missing cleanup,
  • warning about deprecated APIs.

If you see a console.log printed twice in development, that’s StrictMode — not a bug. It has no effect in production builds. Keep it on.

Production builds

Terminal
npm run build     # creates dist/ with optimised, minified files
npm run preview   # serves dist/ locally to check the build

The dist/ folder contains plain HTML, JS and CSS you can host anywhere — covered in Deploying React apps.

React Developer Tools

Install the React Developer Tools browser extension (Chrome Web Store, Firefox Add-ons or Edge Add-ons). It adds two tabs to your browser’s DevTools:

  • ⚛ Components — browse your component tree, and see and edit each component’s props, state and hooks live.
  • ⚛ Profiler — record interactions and see which components rendered and how long they took.

You’ll use the Components tab constantly to answer “what state does this component have right now?”

Other ways to start

Command When to use it
npm create vite@latest learning, SPAs, dashboards, embedding React in existing pages
npx create-next-app@latest full-stack sites with server rendering and Server Components
npx create-react-router@latest React Router in framework mode with SSR and data loading

Avoid tutorials that use Create React App (create-react-app) — it was deprecated in 2025 and no longer maintained.

Tip: keep the dev server running in one terminal while you work, and keep the browser console open. React’s warnings in the console are some of the most helpful error messages in web development.

Exercise

Create and customise your first app

Create a new Vite React project called course-catalog, install its dependencies and start the dev server. Replace the contents of src/App.jsx with a component that renders an <h1> saying “Course Catalog” and a paragraph with today’s date (use new Date().toLocaleDateString()). Delete App.css and its import. Check that the page updates instantly when you save.

Terminal
npm create vite@latest course-catalog -- --template react
# then…

Summary

  • npm create vite@latest my-app -- --template react creates a ready-to-run React project.
  • npm run dev starts a dev server with hot module replacement; npm run build makes a production bundle.
  • index.html loads src/main.jsx, which renders <App /> into the #root element.
  • <StrictMode> runs extra development-only checks that catch common bugs.
  • Install React Developer Tools to inspect components, props and state in the browser.