Setting up a React project
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
- 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+. - A code editor — VS Code is the most common choice. Useful extensions: ESLint or Oxc for linting, Prettier for formatting.
- A modern browser — Chrome, Edge or Firefox, with React Developer Tools installed (more on that below).
Create the project
npm create vite@latest course-catalog -- --template react
cd course-catalog
npm install
npm run devnpm create vite@latestdownloads Vite’s project generator.--template reactpicks the React + JavaScript template. Usereact-tsfor TypeScript (see React with TypeScript).npm installdownloads React, Vite and the other dependencies.npm run devstarts the dev server. Open the URL it prints — usuallyhttp://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
index.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
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
{
"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-reactplugin 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 youimportfrom 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
npm run build # creates dist/ with optimised, minified files
npm run preview # serves dist/ locally to check the buildThe 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.
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.
npm create vite@latest course-catalog -- --template react
# then…npm create vite@latest course-catalog -- --template react
cd course-catalog
npm install
npm run dev
# src/App.jsx
# function App() {
# return (
# <main>
# <h1>Course Catalog</h1>
# <p>Today is {new Date().toLocaleDateString()}</p>
# </main>
# );
# }
#
# export default App;Summary
npm create vite@latest my-app -- --template reactcreates a ready-to-run React project.npm run devstarts a dev server with hot module replacement;npm run buildmakes a production bundle.index.htmlloadssrc/main.jsx, which renders<App />into the#rootelement.<StrictMode>runs extra development-only checks that catch common bugs.- Install React Developer Tools to inspect components, props and state in the browser.