Skip to content

Build a to-do app in React

BasicsBuild alongReact + ViteYou need: basic JavaScript, Node installed
What you’ll build: A to-do list you can add to, tick off and clear. Seven steps, each a small change, and a check in the browser after each one.JSX TodoItem componentkey A list from an arraystate useState for todos and textform Add, tick and delete
Step 1 of 7

Set up React and Vite by hand

Make a folder todo and add five small files. package.json lists React and Vite; index.html is the page; src/main.jsx puts your App component into the page's #root div.

Then run npm install. Vite is the dev server: it turns your JSX into plain JavaScript and reloads the page when you save.

WHY

Writing the files yourself shows there is no magic: a React app is one HTML page, one script that calls createRoot, and components. npm create vite makes the same files plus a few extras.

This step runs:
terminal
$ mkdir todo && cd todo
$ npm install
package.jsonnew+18−0
Added: {
Added: "name": "todo",
Added: "private": true,
Added: "version": "0.0.0",
Added: "type": "module",
Added: "scripts": {
Added: "dev": "vite",
Added: "build": "vite build"
Added: },
Added: "dependencies": {
Added: "react": "^19.3.1",
Added: "react-dom": "^19.3.1"
Added: },
Added: "devDependencies": {
Added: "@vitejs/plugin-react": "^6.1.2",
Added: "vite": "^8.3.5"
Added: }
Added: }
index.htmlnew+12−0
Added: <!doctype html>
Added: <html lang="en">
Added: <head>
Added: <meta charset="UTF-8" />
Added: <meta name="viewport" content="width=device-width, initial-scale=1.0" />
Added: <title>To-do</title>
Added: </head>
Added: <body>
Added: <div id="root"></div>
Added: <script type="module" src="/src/main.jsx"></script>
Added: </body>
Added: </html>
vite.config.jsnew+6−0
Added: import { defineConfig } from 'vite';
Added: import react from '@vitejs/plugin-react';
Added:
Added: export default defineConfig({
Added: plugins: [react()],
Added: });
src/main.jsxnew+9−0
Added: import { StrictMode } from 'react';
Added: import { createRoot } from 'react-dom/client';
Added: import App from './App.jsx';
Added:
Added: createRoot(document.getElementById('root')).render(
Added: <StrictMode>
Added: <App />
Added: </StrictMode>
Added: );
src/App.jsxnew+3−0
Added: export default function App() {
Added: return <h1>To-do</h1>;
Added: }

Where to go next

Was this tutorial useful?Your vote tells us what to improve next.
Did a step not work, or something unclear?