EduFlow
React Fundamentals
0%

Section 1 · Getting Started

Setting Up with Vite

14 min4 min readPut in order

Lesson at a glance

Create a React 19 project with Vite, run the dev server, and trace how index.html, main.jsx and App.jsx connect so you know where every change goes.

  1. 1Create the project
  2. 2How the pieces connect
  3. 3StrictMode, briefly
  4. 4The four scripts

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

A React project needs more than React. Browsers don’t understand JSX, your code is split into dozens of modules, and you want the page to update the moment you save a file. A build tool handles all of that. In 2026 the default choice for a client-side React app is Vite: it starts in well under a second, updates the browser on save, and produces a small optimized build when you’re ready to ship.

Create the project

Check your Node.js version first. Current Vite (7 and 8) needs Node 20.19+ or 22.12+; in practice, install a current LTS release (22 or 24), since Node 20 reached end of life in April 2026.

Terminal
node -v
# v24.x or v22.x: a current LTS release

Then scaffold the Watchlist project:

Terminal
npm create vite@latest watchlist -- --template react
cd watchlist
npm install
npm run dev

The -- matters. It tells npm “everything after this belongs to the tool I’m running”, so --template react reaches create-vite instead of being eaten by npm. @latest always gives you the newest major version of Vite (Vite 8 at the time of writing); everything in this course works the same on Vite 7 or 8. Recent versions of create-vite may also offer to install dependencies and start the server for you; accepting is fine.

The terminal prints a local URL, http://localhost:5173/. Open it and you’ll see the Vite + React starter page with a counter button.

How the pieces connect

Open the folder in your editor. Most files are configuration you won’t touch often. Three files matter right now, and they form a chain.

The browser loads index.html, which contains a root div and a module script pointing at src/main.jsx. main.jsx calls createRoot on the root div and renders App from src/App.jsx. index.html <div id="l-rf-1-2-root"> <script type= "module" src=…> src/main.jsx createRoot(root) .render(<App />) src/App.jsx export default function App() loads → mounts → renders
From index.html to your App component

index.html sits at the project root, not in a public folder. Vite treats it as the entry point. It contains an empty <div id="root"></div> and one script tag: <script type="module" src="/src/main.jsx"></script>.

src/main.jsx is where React takes over:

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>,
);

createRoot takes a real DOM node and returns a root that React manages from then on. Everything inside #root now belongs to React; don’t change it with document.querySelector code of your own.

src/App.jsx is your first component and where you’ll spend most of your time. Replace its contents with something of your own to prove the chain works:

src/App.jsx
export default function App() {
  return <h1>My Watchlist</h1>;
}

Save, and the browser updates without a reload. That’s hot module replacement (HMR) with React Fast Refresh, set up by the @vitejs/plugin-react plugin in vite.config.js. You can also delete src/App.css and empty src/index.css; you’ll style the app properly later.

StrictMode, briefly

<StrictMode> adds extra checks in development. It renders each component twice and runs effects twice (mount, clean up, mount again) to flush out code that isn’t safe to repeat. If you see a log print twice in dev, this is why. It does nothing in production, so leave it on. It will matter when you reach effects in Section 3.

The four scripts

package.json defines the commands you’ll use:

Command What it does
npm run dev Starts the dev server with instant updates
npm run build Bundles and minifies the app into dist/
npm run preview Serves dist/ locally to check the real build
npm run lint Runs the linter, including the Rules of Hooks

The rest of the folder is supporting cast. package.json lists your dependencies (react, react-dom) and dev tools (vite, @vitejs/plugin-react and a linter). node_modules/ is where npm install puts them; it’s large, it’s rebuilt from package.json at any time, and it never goes into Git. public/ holds files served as-is at the site root, such as a favicon. The linter’s config file depends on the template version: current templates use Oxlint (.oxlintrc.json), older ones and the ESLint option use eslint.config.js.

dist/ is generated output. Never edit files in it, and don’t commit it to Git; the starter’s .gitignore already excludes it. When you deploy in the last section, Vercel will run npm run build for you.

Your project is running and you know where React is mounted. If the dev server ever gets into a strange state after you install a package or rename files, stop it with Ctrl+C and run npm run dev again. A restart takes a second and fixes more problems than it should. Next, you’ll write your first real component in App.jsx and split the Watchlist into reusable pieces.

Key takeaways

  • npm create vite@latest watchlist -- --template react scaffolds a React project; npm run dev serves it at localhost:5173 with hot updates.
  • The browser loads index.html, which loads src/main.jsx, which mounts the App component into the div with id root.
  • npm run build writes an optimized static site to dist/, and npm run preview serves that build locally.
  • StrictMode renders components twice and runs effects twice in development only, to surface bugs early.

Further reading

Check your understanding

4 questions

Question 1 of 4

You run npm create vite@latest watchlist --template react with npm 10, and Vite asks you to pick a framework anyway. Why?

Question 2 of 4

Where does React actually attach your app to the page in a Vite project?

Question 3 of 4

In development, a console.log at the top of your App component prints twice on load. In the production build it prints once. What’s going on?

Question 4 of 4

You want to see exactly what your users will download before deploying. Which command sequence fits?

Practice

Put in order

Set up the Watchlist project

You’re on a fresh laptop with Node.js installed. Put these steps in the order you’d run them to get the Watchlist project running and showing your own heading in the browser.

Use the arrow buttons to reorder.

  1. 1npm run dev, then open http://localhost:5173
  2. 2node -v — confirm Node.js 20.19+ or 22.12+
  3. 3npm create vite@latest watchlist -- --template react
  4. 4cd watchlist
  5. 5Replace src/App.jsx with your own <h1>My Watchlist</h1> and save
  6. 6npm install