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.