← Level 3 – Master

Lesson 3 of 10 ⏱ 35 minutes Premium

Your first React app with Vite

Set up a real React project, run it, and get your bearings in what was created.

Show me: setting up the project

Vite (pronounced “veet,” French for “fast”) is a tool that prepares a ready-made React project skeleton for you. Open the terminal and move to where you want the project to live (like your Desktop):

cd Desktop
npm create vite@latest my-react-web -- --template react

Vite might ask you something – confirm with Enter. Then:

cd my-react-web
npm install
npm run dev -- --port 3901

Do you see a spinning logo and the heading “Vite + React”? Congratulations – your first React app is running! 🎉

💡

What is localhost? A “server” running only on your computer. Only you can see it – it’s your private testing ground. And the best part: when you change the code and save, the page refreshes itself instantly. No more endless F5!

A tour of the project

Open the my-react-web folder in VS Code (File → Open Folder). It looks like a lot of files, but only three matter to you right now:

FileWhat it is
index.htmlthe only HTML on the whole website – almost empty, just a <div id="root">
src/main.jsxthe starter: takes the app and inserts it into that div
src/App.jsxthe main component – this is where you’ll write code
src/App.cssstyles – plain CSS, just like you know it

Ignore the rest for now (never open or delete node_modules, package.json is a list of the project’s packages).

Your first change to the code

Open src/App.jsx. Delete everything and write:

function App() {
  const name = "Jake";

  return (
    <div>
      <h1>Hi, this is {name}!</h1>
      <p>This is my first React app.</p>
    </div>
  );
}

export default App;

Save – and the page in the browser changed on its own. Here’s what you’re looking at:

JSX has two quirks you’ll get used to: instead of class, you write className (class is a reserved word in JavaScript), and a component must return one wrapper element (that’s why there’s a <div> around everything).

Your turn 💪

  1. Set up the project following the guide and get it running.
  2. Edit App.jsx: a heading with your name, a paragraph about what you’re building, and a variable age that you display in the sentence I am {age} years old.
  3. Deliberately delete a closing tag and see what the error looks like – Vite shows it right in the browser, with the line number. Then fix it.
  4. Stop the server (Ctrl+C in the terminal) and start it again (npm run dev -- --port 3901) – to get the whole cycle under your fingers.

Check yourself: The project runs on localhost, you can stop and start it, and when you edit App.jsx and save, the browser redraws itself. The developer’s cycle is spinning!

What to take away from this lesson