Running React for real: Vite
So far you have read JSX on the page. To run it on your machine you need one more piece: a build step. Browsers only execute plain JavaScript, and JSX is not plain JavaScript, so a tool must compile every <h1>...</h1> into the function calls you met in lesson 2-2 before the browser sees it. This is not optional ceremony, it is the reason our sandbox exercises use plain JavaScript, and it is the first thing you do at any React job: clone the project, install, start the dev tool.
The standard tool today is Vite (pronounced "veet", French for fast). It compiles JSX, serves your app locally while you work, and rebuilds the page the instant you save a file, a feature called hot reload.
Create and run a React project with Vite. You need Node.js installed (it ships with npm, the package manager from Advanced JavaScript). Follow along on your own machine, this is the exact sequence used to start every project in this course from here on.
Step 1/3: Scaffold a new React project. npm create downloads Vite's project template and fills in a folder named task-tracker with the react template:
The files that matter
The template creates more files than you need to care about today. Three do the work:
index.html— the single page. It contains<div id="root"></div>and a script tag pointing atsrc/main.jsx.src/main.jsx— the entry point. It runs thecreateRoot(...).render(<App />)call from lesson 2-1, exactly the code you already read.src/App.jsx— theAppcomponent. This is where you work. Replace its contents with your own component, save, and the browser updates instantly.
One convention to notice: component files use the .jsx extension so tools know the file contains JSX, and each component typically lives in its own file, exported with export default App and imported where it is used, the module syntax from Advanced JavaScript.
Quiz
Why does React code need a build step before a browser can run it, while the plain JavaScript in this course's sandbox does not?
Problem
You cloned a teammate's Vite React project. In order, what two npm commands get it running in your browser?