Skip to main content
Frontend tutorial

3.1. Follow the page into App

In a fresh Vite project, the browser opens index.html first. It's almost empty:

index.html
<body>
<!-- Place where the React app will be rendered -->
<div id="root"></div>
<!-- Script that renders the React app -->
<script type="module" src="/src/main.tsx"></script>
</body>

The script is src/main.tsx. It creates the React app in the root div:

src/main.tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css' // importing global styles
import App from './App.tsx'

// Render React in the root div
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

So App is the first component that we render, and it's the file in the editor: the template's demo page. Click Count is 0 a few times. Then delete all the things we don't need: the logo with its import, the paragraph and the Documentation section. Keep the heading and the button, and change the heading to Counter.

Need a hint?
  • Keep useState, the heading and the button. Everything else in the JSX can go.
  • With one section left, the <> fragment around it can go too.

The preview follows every edit. In the end it shows only the heading and the button, and the button still counts.

Work locally

You need Node.js 24, pnpm and Git (how to set them up). Clone this step’s starting code:

git clone --depth 1 \
--branch lesson-03-01-follow-the-page-start-v6 \
https://github.com/adam-zielonka/frontend-tutorial.git \
03-01-follow-the-page
cd 03-01-follow-the-page
pnpm install --frozen-lockfile
pnpm dev

To keep your own commits: git switch -c my-work.

Browse the source on GitHub (opens in a new tab)

Bring your browser edits

Choose Download my files in the ⋯ menu. It saves the lesson’s files as JSON. Stop the local server with Ctrl+C, copy the download into the project folder and run:

node import-draft.mjs ./03-01-follow-the-page-my-files.json
pnpm dev

The import replaces the project’s exercise files, so commit or back up local edits first.

Loading this step’s code…
Starting the live preview…