Skip to Content
React in a Week
Day 0 · Start here

Create your first app

Use Vite to create the Reading List project, run it in your browser, and take a tour of the files it made.

A React project needs a few things wired together before you can see anything: a web page, a way to turn your modern JavaScript into something the browser can load, and a server that reloads the page when you save. Setting that up by hand is tedious, so you will use a tool that does it for you.

That tool is Vite (pronounced "veet", the French word for "fast"). It creates a project in seconds and reloads your app the instant you save a file. It is one of the build tools react.dev recommends for starting a React app from scratch.

Create the project

Pick a folder

In your terminal, go to the folder where you keep projects. For example, to use your Documents folder:

cd Documents

cd means "change directory". It moves your terminal into that folder.

Run the create command

npm create vite@latest reading-list -- --template react

This downloads the latest Vite project creator and asks it to make a folder called reading-list using the plain JavaScript React template. The extra -- passes --template react through npm to Vite.

Answer the prompts

Vite may ask you a couple of questions. Use the arrow keys and Enter:

  • Which linter to use? Pick Oxlint (the default) or ESLint. Either is fine.
  • Install with npm and start now? Pick Yes.

If you picked Yes, Vite installs everything and starts the app. Skip to the next section.

If you picked No (or nothing started)

Run these three commands yourself:

cd reading-list
npm install
npm run dev

npm install downloads React and the other packages listed in package.json into a folder called node_modules. npm run dev starts the development server.

When the dev server is running, the terminal shows something like this:

  VITE v8.3.6  ready in 312 ms

  ->  Local:   http://localhost:5173/

Open http://localhost:5173 in your browser. You should see the Vite and React starter page with a counter button. Click it a few times.

Keep this terminal open while you work. The dev server stops when you close it or press Ctrl + C. To start it again later, open a terminal in the reading-list folder and run npm run dev.

A tour of the project

Open the reading-list folder in VS Code (File → Open Folder). Here are the files that matter right now:

reading-list/
├── index.html        the one HTML page your app lives in
├── package.json      the project's name, scripts and dependencies
├── vite.config.js    Vite settings (you will not touch this for a while)
├── node_modules/     downloaded packages (never edit this)
├── public/           static files such as the favicon
└── src/
    ├── main.jsx      the entry point: starts React
    ├── App.jsx       your top-level component
    ├── App.css       styles for the starter page
    ├── index.css     global styles for the starter page
    └── assets/       images used by the starter page

The interesting part is how three files hand off to each other.

index.html is a nearly empty page. Its body holds a single empty element, <div id="root"></div>, and a script tag that loads src/main.jsx.

src/main.jsx finds that empty div and tells React to take control of it:

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 creates a root, the place where React draws your app. .render(<App />) tells React what to draw there: your App component. StrictMode is a helper that runs extra checks while you develop, to warn you about common bugs. It has no effect in the final, published app.

src/App.jsx is where your own code goes. It exports a function called App, and whatever that function returns is what you see on the page.

You do not need to understand every line of main.jsx yet. You will write it once per project and then rarely look at it again.

Here is the same setup in a sandbox. The index.js tab plays the role of main.jsx. Change the text in App.js and watch it update.

Live code· How the files connect
Deep diveWhy .jsx locally but .js in the sandboxes?

Files that contain JSX (the HTML-like syntax you will learn on Day 1) are usually named .jsx in Vite projects, and Vite expects that. The sandboxes in this course are more relaxed and use .js. The code inside is identical. When a sandbox shows BookCard.js, the file in your own project is src/BookCard.jsx.

Clean out the starter

The starter page is nice, but you want a blank canvas for the Reading List. Make three changes:

  1. Open src/App.jsx, delete everything, and replace it with:

    src/App.jsx
    export default function App() {
      return <h1>My Reading List</h1>
    }
  2. Open src/App.css and delete everything in it, leaving an empty file.

  3. Open src/index.css and delete everything in it too.

Save. The browser updates by itself, without a refresh, and shows a plain "My Reading List" heading. This instant update is called Hot Module Replacement (HMR).

Look inside with React DevTools

With your app open in the browser, open the browser's developer tools (F12, or Cmd + Option + I on macOS). Find the Components tab that React Developer Tools added. You may need to click the >> arrow to see it.

You should see a tree with a single entry: App. That is your component. As your app grows this week, this tree will grow with it, and it is one of the best ways to understand what React is doing.

Try it

Make it yours

Change the heading so it shows your name, for example "Ada's Reading List". Then add a second line under the heading that says how many books you hope to read this year.

Hint: a component can only return one outer tag, so wrap both lines in a <div>.

Live code· Challenge: make it yours
Show solution
src/App.jsx
export default function App() {
  return (
    <div>
      <h1>Ada's Reading List</h1>
      <p>Goal: 12 books this year</p>
    </div>
  )
}

The round brackets let the returned markup span several lines. The outer <div> is needed because a component returns one thing. You will learn the exact rule, and a neater way around it, in the JSX lesson on Day 1.

Quick check

Which file does Vite load first, and which element does React draw your app into?

Quick check

You closed your terminal and the app at localhost:5173 stopped loading. What should you do?

Day 0 progress

0/3

On this page