Setting Up with Vite
React does not have an official CLI the way Angular does. The recommended way to start a new React project is Vite — a fast build tool that handles the module bundling, hot module replacement, and development server that React needs to run in a browser.
Why Vite
Section titled “Why Vite”Browsers cannot execute JSX or ES modules the way React uses them directly. A build tool transforms your source code — JSX into React.createElement calls, imports into a bundle — so the browser can run it.
Vite is faster than older tools like Create React App because it serves your source files as native ES modules during development instead of bundling everything upfront. Changes appear in the browser almost instantly.
Scaffolding the project
Section titled “Scaffolding the project”Run this in your terminal from wherever you keep your projects:
npm create vite@latest zero-budget -- --template reactcd zero-budgetnpm installnpm run devnpm create vite@latest downloads and runs the Vite scaffolding tool. --template react selects the JavaScript React template (not TypeScript — this course uses JavaScript). The -- separator passes the remaining flags to the scaffolding tool rather than to npm.
After npm run dev you will see a URL — usually http://localhost:5173 — and the default Vite React welcome page in your browser.
What was generated
Section titled “What was generated”Open the project in your editor. The important files:
zero-budget/├── index.html ← entry point the browser loads├── vite.config.js ← Vite configuration├── package.json ← dependencies and scripts└── src/ ├── main.jsx ← mounts the React app into index.html ├── App.jsx ← root component ├── App.css ← styles for App └── index.css ← global stylesindex.html is the file the browser actually loads. It has one <div id="root"> where your entire React app will be injected.
src/main.jsx finds that div and tells React to take it over:
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>,)src/App.jsx is your root component. It is just a JavaScript function that returns JSX. Everything you build will eventually render through here.
The .jsx extension
Section titled “The .jsx extension”Files containing JSX use the .jsx extension. Plain JavaScript files use .js. Vite uses the extension to know which files to transform. You will use .jsx for any file that returns JSX — which is most of your component files.
Exercise
Section titled “Exercise”- Scaffold a new React project using the command above.
- Open
src/App.jsxand change the text inside the<h1>tag toHello ZeroBudget. - Save the file. The browser should update without a full page reload — that is Vite’s hot module replacement.
- Open
src/main.jsxand read through it. What doescreateRootdo? What does.render()do?
- Vite is the recommended tool for scaffolding and running React projects.
npm create vite@latest project-name -- --template reactgenerates a ready-to-run project.- The browser loads
index.html, which contains a<div id="root">. src/main.jsxmounts the React app into that div usingcreateRoot.src/App.jsxis the root component — the starting point for your UI.