Web frameworks · Beginner · 18 min
How to Build a React 19 App with Vite
By Padding · Updated 15 Nov 2026
React 19.3 · Vite 8 · Node.js 26
You will scaffold a React 19 and TypeScript app with Vite 8, run the dev server, replace the starter page with a small checklist built from components and state, then create a production build and serve it locally.
On this page
React builds user interfaces from components, which are functions that return a piece of the page. Vite is the tool that serves your code while you work on it and bundles it for production. Vite starts in well under a second and updates the browser the moment you save a file.
In this tutorial you create a project from Vite's React and TypeScript template, look at what it gives you, and replace the demo with a small checklist. The checklist covers the three ideas you use in every React app: components, props and state. At the end you build the app for production and serve that build. It assumes Node.js 26 from the Node.js install tutorial.
Step 1 · Create the project
Vite's scaffolding tool is create-vite, which npm create vite runs. The --template react-ts option picks React with TypeScript, and --no-interactive skips the questions so the command is repeatable:
cd ~
npm create vite@9 checklist -- --template react-ts --no-interactive
cd checklist
npm installThe double dash passes everything after it to create-vite and not to npm. npm install downloads the dependencies listed in package.json.
Check it worked
The scaffolding command ends with Done. Now run: and a few lines of instructions. Look at the files it made:
ls
cat package.jsonYou see index.html, package.json, vite.config.ts, src/, three tsconfig files, and public/. package.json lists react and react-dom at version 19 under dependencies, and vite, typescript and @vitejs/plugin-react under devDependencies. It defines four scripts: dev, build, lint and preview.
Step 2 · Run the dev server
Start the development server. It keeps running in the terminal, so open a second terminal in the same folder (cd ~/checklist) for the commands that follow:
npm run devThe first terminal prints VITE v8. and a version number, then Local: http://localhost:5173/. In the second terminal, fetch the page:
curl -s http://localhost:5173/Check it worked
The response is a short HTML page with <div id="root"></div> and a script tag pointing at /src/main.tsx. Vite also adds a few helper scripts for hot reloading. Open the same address in a browser, and you see the Vite and React starter page with a counter button. Vite serves your source files as they are and lets the browser load them as modules, which is why startup is so quick. The empty root element is where React draws the interface.
If you are working on a remote server, the dev server only listens on localhost by default. Either forward the port over SSH from your own computer, or start the server with npm run dev -- --host to listen on all interfaces. Do the second only on a trusted network, because the dev server is not meant to be public.
Stop the server before the next step by pressing Ctrl+C in the terminal where it runs.
Step 3 · Read the entry points
Two small files start the app. index.html loads the script, and src/main.tsx hands React the root element:
cat src/main.tsxThe file creates a React root with createRoot from react-dom/client, and renders <App /> inside <StrictMode>. In development, StrictMode runs some code twice to expose bugs, such as effects that do not clean up after themselves. It does nothing in a production build. App comes from src/App.tsx, and that is the file you edit next.
Step 4 · Build a checklist
Replace src/App.tsx with a component that keeps a list of items in state. It has a child component for each row, a form to add items, and a counter of what remains:
cat > src/App.tsx <<'TSX'
import { useState } from 'react'
import './App.css'
type Item = { id: number; text: string; done: boolean }
type RowProps = {
item: Item
onToggle: (id: number) => void
}
function Row({ item, onToggle }: RowProps) {
return (
<li>
<label className={item.done ? 'done' : undefined}>
<input
type="checkbox"
checked={item.done}
onChange={() => onToggle(item.id)}
/>
{item.text}
</label>
</li>
)
}
export default function App() {
const [items, setItems] = useState<Item[]>([
{ id: 1, text: 'Install Node.js 26', done: true },
{ id: 2, text: 'Create a Vite project', done: true },
{ id: 3, text: 'Build my own component', done: false },
])
const [text, setText] = useState('')
function toggle(id: number) {
setItems(items.map((item) =>
item.id === id ? { ...item, done: !item.done } : item,
))
}
function add(event: React.FormEvent) {
event.preventDefault()
const trimmed = text.trim()
if (trimmed === '') return
const id = Math.max(0, ...items.map((item) => item.id)) + 1
setItems([...items, { id, text: trimmed, done: false }])
setText('')
}
const remaining = items.filter((item) => !item.done).length
return (
<main className="checklist">
<h1>Checklist</h1>
<p>{remaining} of {items.length} left</p>
<ul>
{items.map((item) => (
<Row key={item.id} item={item} onToggle={toggle} />
))}
</ul>
<form onSubmit={add}>
<input
value={text}
onChange={(event) => setText(event.target.value)}
placeholder="Add an item"
aria-label="New item"
/>
<button type="submit">Add</button>
</form>
</main>
)
}
TSX
cat > src/App.css <<'CSS'
.checklist {
max-width: 28rem;
margin: 3rem auto;
padding: 0 1rem;
text-align: left;
}
.checklist ul {
list-style: none;
padding: 0;
}
.checklist li {
padding: 0.4rem 0;
}
.checklist .done {
text-decoration: line-through;
opacity: 0.6;
}
.checklist form {
display: flex;
gap: 0.5rem;
margin-top: 1rem;
}
.checklist form input {
flex: 1;
}
CSSThe pieces to understand:
useStategives a component memory.const [items, setItems] = useState(...)returns the current value and a function that replaces it and redraws the component. You never changeitemsdirectly. You always build a new array or object, astoggleandadddo.- Props are the arguments of a component.
Rowreceives anitemand anonTogglefunction from its parent, and itsRowPropstype describes them. key={item.id}gives React a stable identity for each row, so it can update the right one when the list changes. Use an ID from your data, never the array position, when items can be reordered or removed.- The inputs are controlled: the screen shows what is in state, and
onChangewrites typed text back into state.
Check the types
TypeScript checks all of this when you build. Run only the type check and the linter, which npm run build and npm run lint use:
npx tsc -b
npm run lintThe type check prints nothing when it passes. The linter prints a summary of how many files it checked and that it found no problems. If you change the state type and forget to update a row, the compiler points at the exact line.
Troubleshooting
If the page is blank in the browser, open the developer console. A red error there names the file and line. If port 5173 is taken, Vite uses 5174 and says so in its output, so read the address it prints.
Step 5 · Build for production
The dev server serves unbundled files. For a real site you build once. Vite then bundles and minifies the code, and writes the result to dist/:
npm run build
ls dist dist/assetsCheck it worked
The build runs the type check first, then Vite, and ends with a list of files and sizes such as dist/index.html and files under dist/assets/ with a hash in the name, followed by built in and a time. The hash changes whenever the content changes, so a browser can cache these files for a long time and still get the new version after a deploy.
Serve the build locally to see exactly what production would serve. It keeps running in the terminal, so use a second terminal again for the curl command:
npm run previewcurl -s http://localhost:4173/ | grep -o '<script[^>]*>'Stop it with Ctrl+C.
The preview server listens on port 4173. The script tag in the output points at a hashed file in /assets/. The preview server is for checking a build on your own machine. For a real site, upload the contents of dist/ to any static host, or serve the folder with a web server such as Nginx. The app is a set of static files and needs no Node.js on the server.
Step 6 · Use environment variables carefully
Vite replaces import.meta.env.VITE_NAME in your code with the value of the variable VITE_NAME at build time. Only variables whose names start with VITE_ reach the browser, on purpose. Anything you put in them ends up in the JavaScript that every visitor downloads. Do not put secrets or private API keys there. A secret that your app needs belongs on a server that your app calls.
Remove the demo project when you are finished:
cd ~
rm -rf ~/checklistNext steps
- Serve the built files with a web server: install Nginx on Ubuntu 26.04.
- Put your site on a free static host: host a static site on Cloudflare Pages.
- Try a framework that adds routing and server rendering: build your first Next.js 16 app with the App Router.
- The React documentation at react.dev and the Vite guide at vite.dev/guide cover effects, context, routing options and plugins.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials