# Todo app

> A React todo app on the Vite dev server, with an API you can curl from bash and code that hot-reloads as you edit it.

Live: https://clientvm.joeldsouza.me/demos/todo-vite-react/ (Chromium) · Source: https://github.com/Reflex-Gravity/client-vm/blob/main/site/src/demos/todo-vite-react.ts

The vite-react-ts preset boots with its node_modules already installed. The demo writes its own files over it: a React app and a small API, written as a Vite dev-server middleware that keeps the todos in todos.json.

The page polls the API, so a todo added with curl from bash, or typed into todos.json in the editor, shows up within a second. Edits to App.tsx or index.css hot-reload without a page reload.

## How it's built

```ts
const app = await vm.createInstance({ preset: 'vite-react-ts' });
await app.fs.writeFile('/home/user/app/src/App.tsx', appSource);

app.onPortOpen((port, url) => (preview.src = url));
await app.exec('npm run dev', { cwd: '/home/user/app' });
```

## Try

- list todos: `curl -s localhost:5173/api/todos`
- add from bash: `curl -s --json '{"title":"Added from bash"}' localhost:5173/api/todos`
- tick #2: `curl -s -X PATCH localhost:5173/api/todos/2`
- count open: `grep -c '"done": false' todos.json`
- type-check: `npx tsc --noEmit -p tsconfig.json && echo types ok`
- git commit: `git init -q && git add . && git commit -qm "todo app" && git log --oneline`

## Built with

Vite 6, React, TypeScript, bash, git

## Docs

- [Presets](https://clientvm.joeldsouza.me/docs/decisions/0018-presets-cached-on-host-origin/)
- [Compatibility](https://clientvm.joeldsouza.me/docs/compatibility/)
