Vibe Coding: build real apps with AI · Episode 12. Every agent run below is real: Claude Code 2.1.319 (model claude-sonnet-5-5) in print mode (claude -p), on 7 November 2026, in /home/ravi/projects/todo-react (a Git repository). The app was tested in Chromium with Playwright against the real Vite dev server. The chai-counter demo is a separate two-file Vite project run on the same Vite 8 / React 19 install. Replies are quoted exactly, shortened where marked ....
Why one file stops working (one cook vs kitchen stations)
Episode 10's to-do app is one 190-line file: HTML, CSS and JavaScript mixed. Every new feature means scrolling through everything.
| A restaurant kitchen | An app |
|---|---|
| one cook does everything | one big file |
| stations: tandoor, curry, counter | components: Header, TaskForm, TaskList |
| one order slip every station reads | shared state: the tasks list |
What React is
React is a free, open-source JavaScript library for building user interfaces. In Episode 10 we wrote render() by hand (wipe the list, rebuild every item). With React you describe what the screen should look like for the current state; when the state changes, React updates only the parts that changed.
One prompt
claude -p "old-index.html is my to-do app from last week, all in one file. Rebuild it as a React app with Vite in this
folder, using JavaScript (not TypeScript). Keep every feature: add, tick, edit, delete, saving in localStorage, syncing
between tabs, and the duplicate check. Split the page into small components, each in its own file. Do not change how it
looks." --allowedTools Read Write Edit Glob "Bash(npm:*)" "Bash(npx:*)" "Bash(ls:*)"
Real log (shortened): a shell heredoc to write package.json was refused (needs approval), so it used Write for 13 files; npm install; npm run build → vite v5.4.21 ... ✓ 37 modules transformed. Reply:
npm run buildsucceeds, but I haven't opened it in a browser or run it ... Nothing is committed.npm installalso printed an audit warning that I didn't look into.
A Vite project
Vite (French for "quick") is a build tool. Its guide (vite.dev, fetched 7 Nov 2026) says it has two parts: "A dev server that provides rich feature enhancements over native ES modules" with "extremely fast Hot Module Replacement (HMR)", and "A build command that bundles your code". The official way to start one is npm create vite@latest; Vite requires Node.js 20.19+ or 22.12+.
todo-react/
├── index.html the one HTML page: <div id="root">
├── package.json the project's name, scripts and libraries
├── vite.config.js
├── node_modules/ the libraries npm downloaded (not in Git)
└── src/
├── main.jsx starts React inside #root
├── App.jsx puts the page together
├── index.css the old styles, unchanged
├── hooks/useTasks.js the task logic + localStorage
└── components/
├── Header.jsx TaskForm.jsx TaskList.jsx
└── TaskItem.jsx EditRow.jsx
$ npm run dev
VITE v5.4.21 ready in 350 ms
➜ Local: http://localhost:5173/
localhost means this computer; a port (5173) is a numbered door for one service on it.
Components (a thali's compartments)
react.dev (fetched 7 Nov 2026): "a React component is a JavaScript function that you can sprinkle with markup", and "their names must start with a capital letter or they won't work!" Lowercase <main> is an HTML tag; <Header /> is a component.
import Header from './components/Header.jsx';
import TaskForm from './components/TaskForm.jsx';
import TaskList from './components/TaskList.jsx';
import { useTasks } from './hooks/useTasks.js';
export default function App() {
const { tasks, addTask, toggleTask, editTask, deleteTask } = useTasks();
return (
<main>
<Header tasks={tasks} />
<TaskForm onAdd={addTask} />
<TaskList tasks={tasks} onToggle={toggleTask}
onEdit={editTask} onDelete={deleteTask} />
</main>
);
}
JSX
JSX "lets you embed markup inside JavaScript" (react.dev). Vite turns it into plain JavaScript before the browser runs it. { } runs JavaScript and shows the result; <> </> is a fragment (return two elements without an extra box).
export default function Header({ tasks }) {
const left = tasks.filter((t) => !t.done).length;
return (
<>
<h1>To-Do</h1>
<div className="count">
{tasks.length ? left + ' of ' + tasks.length + ' remaining' : ''}
</div>
</>
);
}
Write className, not class. Real warning from React 19.3.1 when we wrote <p class="big">:
Invalid DOM property `class`. Did you mean `className`?
Props (the order slip you hand a cook)
Props (properties) are data passed into a component, written like attributes: <Header tasks={tasks} />. A component reads its props and does not change them. A prop can be a function (onAdd={addTask}) that the child calls to tell the parent something happened.
State with useState
The obvious way fails:
export default function ChaiCounter() {
let cups = 0;
function addCup() {
cups = cups + 1;
console.log('cups is now', cups);
}
return (
<div>
<p>Chai cups today: {cups}</p>
<button onClick={addCup}>+1 chai</button>
</div>
);
}
Real result after 3 clicks:
screen: Chai cups today: 0
console: cups is now 1 | cups is now 2 | cups is now 3
React only redraws a component when it is told something changed; a normal variable tells it nothing, and each redraw runs the function from the top again.
The fix:
import { useState } from 'react';
export default function ChaiCounter() {
const [cups, setCups] = useState(0);
function addCup() {
setCups(cups + 1);
console.log('cups is now', cups);
}
...
screen: Chai cups today: 3
console: cups is now 0 | cups is now 1 | cups is now 2
useState(0) gives the current value and a setter. Calling the setter stores the new value and asks React to redraw. The new value arrives on the next render, which is why the log is one behind. useState is a hook: a React function whose name starts with use, called at the top of a component.
In the app, TaskForm keeps the input text in state (a controlled input):
export default function TaskForm({ onAdd }) {
const [value, setValue] = useState('');
const [dupMsg, setDupMsg] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
const v = value.trim();
if (!v) return;
const dup = onAdd(v);
setDupMsg(dup ? 'That task is already on the list.' : '');
if (!dup) setValue('');
};
...
<input type="text" value={value} onChange={handleChange} ... />
The tasks, localStorage and tab sync live in a custom hook, useTasks.js (71 lines), so the components stay small.
Hot reload (HMR)
Real test against the dev server:
dup: That task is already on the list. | count 3
after reload: [ 'Buy milk', 'Finish episode 9 homework', 'Call Asha about rent' ]
tab A live: [ ..., 'Pay electricity bill' ]
tab B after reload: [ ..., 'Pay electricity bill', 'Book train ticket' ]
# edit Header.jsx while the page is open: <h1>To-Do</h1> → <h1>Ravi's To-Do</h1>
h1 now: Ravi's To-Do | page reloaded? false
Hot Module Replacement swaps the changed file into the running page; the tasks and your typing stay.
The AI's real mistake: versions from memory
$ cat package.json
"react": "^18.3.1", "react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.4", "vite": "^5.4.11"
$ npm view vite version → 8.3.6
$ npm view react version → 19.3.1
$ npm audit
esbuild <=0.24.2
Severity: moderate
esbuild enables any website to send any requests to the development
server and read the response
vite <=6.4.3
Depends on vulnerable versions of esbuild
2 vulnerabilities (1 moderate, 1 high)
The agent wrote package.json from memory instead of using the official scaffold, so it got old versions. npm audit checks your libraries against a list of known security problems.
claude -p "npm audit says: "2 vulnerabilities (1 moderate, 1 high)" ... npm view says the latest versions today are vite
8.3.6, react 19.3.1 and @vitejs/plugin-react 6.2.1. Your package.json has vite ^5.4.11 and react ^18.3.1. Upgrade to the
current versions, fix anything that breaks, and make sure npm audit shows 0 vulnerabilities and npm run build works. Do
not change the app itself." --allowedTools Read Edit "Bash(npm:*)" "Bash(npx:*)"
Real reply (shortened): it installed the new versions, searched src/ for APIs React 19 removed and found none, npm audit → found 0 vulnerabilities, and: "I only ran the build. I didn't start the dev server or click through the app in the browser."
So we re-ran everything on Vite 8:
VITE v8.3.6 ready in 225 ms
dup: That task is already on the list. | count 3
tab B after reload: [ ..., 'Pay electricity bill', 'Book train ticket' ]
h1 now: Ravi's To-Do | page reloaded? false
npm run build
$ npm run build
✓ 22 modules transformed.
dist/index.html 0.35 kB │ gzip: 0.26 kB
dist/assets/index-C76r82Jv.css 1.79 kB │ gzip: 0.78 kB
dist/assets/index-CWlHCraZ.js 222.76 kB │ gzip: 69.76 kB
✓ built in 118ms
The build bundles all files into a few small ones in dist/: that folder is what gets put online (Episode 35).
caca56b Upgrade to Vite 8 and React 19 (npm audit: 0)
acc7e4d React + Vite version (AI)
0b8260c Old to-do app (one file)
Common mistakes (real)
| Mistake | What you see | Why | Fix |
|---|---|---|---|
let cups = 0; cups++ |
console 3, screen 0 | React never hears about a normal variable | const [cups, setCups] = useState(0) |
<p class="big"> |
Invalid DOM property \class`. Did you mean `className`?|classis a JavaScript word |className` |
||
| Versions from the AI's memory | 2 vulnerabilities (1 moderate, 1 high) |
training data is old | npm view, npm audit, upgrade, re-test |
| "The build works, done" | untested features | a build only checks that the code compiles | run the app and the checklist |
Mini project
Ask an AI to add a filter bar (All / Active / Done) as a new component, FilterBar.jsx, with the current filter kept in state in App. Then run npm audit, the six-item checklist from Episode 10, and edit a component with the page open to see hot reload.
What a good outcome looks like
FilterBar receives filter and onChange as props; App holds const [filter, setFilter] = useState('all'); TaskList receives only the filtered tasks; the counter still counts all tasks; npm audit shows 0 vulnerabilities; all checklist items pass.
Practice questions
- Why must
TaskListstart with a capital letter?
Answer
React treats lowercase tags as HTML elements; components must start with a capital letter.
- What's the difference between props and state?
Answer
Props are passed in by the parent and read-only for the child; state is owned and changed by the component itself (with its setter).
- After
setCount(count + 1), why doesconsole.log(count)on the next line show the old number?
Answer
The setter schedules a redraw; the new value is available on the next render.
- What does
npm auditdo?
Answer
Checks the installed packages against a database of known vulnerabilities and suggests fixes.
- What's in
dist/afternpm run build, and what is it for?
Answer
The bundled, minified HTML, CSS and JavaScript of the app: the files you deploy.
Quiz
function Likes() {
const [likes, setLikes] = useState(10);
return (
<button onClick={() => setLikes(likes + 1)}>
{likes} likes
</button>
);
}
After one click, what does the button show? A) 10 likes B) 11 likes C) 1 likes D) it crashes
Answer
B) "11 likes": setLikes stores 11 and tells React to redraw.
Interview questions
- What is a React component? What does it return?
- Explain props vs state with an example.
- Why can't you change state by assigning to a variable?
- What is a controlled input?
- What does a bundler/build tool like Vite do, and what is HMR?
- How do you keep a project's dependencies secure?
Glossary
| Term | Meaning (plain words) | Example |
|---|---|---|
| React | a JavaScript library that draws the screen from state | the to-do app |
| Component | a function that returns a piece of the page | Header |
| JSX | HTML-like markup written inside JavaScript | <h1>To-Do</h1> |
{ } in JSX |
run JavaScript and show the result | {tasks.length} |
| Fragment | <> </>: return several elements without an extra box |
Header |
className |
JSX's name for the HTML class attribute |
className="count" |
| Props | data passed into a component | <Header tasks={tasks} /> |
| Function prop | a function passed in so the child can report back | onAdd={addTask} |
| State | a value a component remembers and changes | the input text |
useState |
React hook that holds state and a setter | const [cups, setCups] = useState(0) |
| Hook | a React function starting with use |
useState, useTasks |
| Custom hook | your own hook that bundles logic | useTasks.js |
| Controlled input | a box whose value comes from state | value={value} |
| Render (React) | React running a component to get its JSX | after setCups |
| Vite | a build tool with a dev server and a bundler | npm run dev |
| npm | Node's package manager: installs libraries | npm install |
| package.json | the project's name, scripts and libraries | "vite": "^8.3.6" |
| node_modules | the folder of downloaded libraries (not in Git) | 20 packages |
| Dependency | a library your project needs | react |
| Dev server | a local server for building, with hot reload | localhost:5173 |
| localhost | this computer | http://localhost:5173/ |
| Port | a numbered door for one service | 5173 |
| HMR / hot reload | swapping a changed file into the running page | the new heading |
| Build | bundling the code into a few small files | npm run build |
| dist | the build's output folder: what you deploy | dist/index.html |
| Version | a numbered release of a package | 5.4.21 → 8.3.6 |
npm view |
prints a package's latest version | npm view vite version |
npm audit |
checks packages for known vulnerabilities | "found 0 vulnerabilities" |
| Vulnerability | a known security weakness | the esbuild dev-server issue |
| Scaffold | generate a new project's starting files | npm create vite@latest |
Summary
React draws the screen from state. Components are capitalised functions returning JSX; props pass data and functions in; useState holds values React remembers and redraws for (a normal variable doesn't work, as the chai counter showed). Vite gives a dev server with hot reload and a build into dist/. The AI wrote package.json from memory with old versions and two audit warnings it "didn't look into"; npm view and npm audit caught it, one prompt upgraded it, and a full re-test proved nothing broke.