Getting Started with React
There are several ways to start a React project. We’ll cover the two most popular modern approaches.
Option 1 โ Vite (Recommended)
Vite is a next-generation build tool that provides blazing fast Hot Module Replacement (HMR) and near-instant server startup.
# Create a new React project with Vite
npm create vite@latest my-app -- --template react
# Navigate into the project
cd my-app
# Install dependencies
npm install
# Start the development server (http://localhost:5173)
npm run dev
Vite Project Structure
my-app/
โโโ public/ โ Static files (served as-is)
โ โโโ vite.svg
โโโ src/
โ โโโ assets/ โ Images, fonts
โ โโโ App.jsx โ Root component
โ โโโ App.css
โ โโโ main.jsx โ Entry point
โ โโโ index.css
โโโ index.html โ HTML shell
โโโ vite.config.js โ Vite configuration
โโโ package.json
Option 2 โ Next.js (Full-Stack)
Next.js adds server-side rendering, file-based routing, and API routes on top of React. Choose it when you need SEO, server components, or a full-stack solution.
npx create-next-app@latest my-app
cd my-app
npm run dev
Essential npm Scripts
| Command | What it does |
|---|---|
npm run dev |
Start development server with HMR |
npm run build |
Create optimised production bundle in dist/ |
npm run preview |
Locally preview the production build |
npm install <pkg> |
Add a dependency |
npm install -D <pkg> |
Add a dev-only dependency |
TipAlways use
npm run dev during development โ never open index.html directly in the browser.Your First Edit
Open src/App.jsx and replace everything with:
function App() {
return (
<div>
<h1>Hello, React! โ๏ธ</h1>
<p>Edit src/App.jsx and save to see changes instantly.</p>
</div>
);
}
export default App;
WarningReact component names must start with a capital letter.
<App /> works; <app /> is treated as an unknown HTML element.