Skip to content
TeachTrails
DevelopmentReact

React Setup with Vite and Bun: Your First React App

Create your first React app with Vite, TypeScript and Bun in 5 minutes, tour every file it makes, and learn the JSX rules that trip up beginners. All tested.

Sukanya Saha, Technology Consultant

8 min read

Beginner friendly

Step 1: Install Bun

Bun installs packages and runs scripts. If you did the Node.js course you already have it.

Terminal
# macOS or Linux
$curl -fsSL https://bun.sh/install | bash
# Windows (PowerShell)
$powershell -c "irm bun.sh/install.ps1 | iex"
$bun --version

Step 2: Create the To-Do app

Terminal
$bun create vite todo-app --template react-ts
$cd todo-app
$bun install
$bun run dev

react-ts means React with TypeScript. When it starts, Vite prints the address of your app:

terminal output
  VITE v8.3.8  ready in 106 ms

  โžœ  Local:   http://localhost:5173/
  โžœ  Network: use --host to expose

Open http://localhost:5173 in your browser. You'll see Vite's starter page with a counter button. Your React app is running.

Step 3: A quick tour of the files

๐Ÿ—‚๏ธ Project folders
todo-app/
โ”œโ”€โ”€ index.html          โ† the one HTML page; has <div id="root">
โ”œโ”€โ”€ package.json        โ† scripts and packages
โ”œโ”€โ”€ vite.config.ts      โ† Vite settings (rarely touched)
โ”œโ”€โ”€ tsconfig*.json      โ† TypeScript settings (already good)
โ”œโ”€โ”€ public/             โ† files served as-is (images, JSON)
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ main.tsx        โ† starts React: draws <App /> into #root
    โ”œโ”€โ”€ App.tsx         โ† YOUR APP STARTS HERE
    โ”œโ”€โ”€ App.css         โ† styles for the starter page (we'll delete it)
    โ”œโ”€โ”€ index.css       โ† global styles
    โ””โ”€โ”€ assets/         โ† starter images (we'll delete them)

Here's the file that starts everything. You'll rarely change it:

src/main.tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)

createRoot finds <div id="root"> in index.html, and React draws <App /> inside it.

Step 4: Make it yours

Delete src/App.css and the src/assets folder, and replace everything in src/App.tsx with this:

src/App.tsx
export default function App() {
  const name = "Asha";
  const tasksToday = 3;

  return (
    <main className="app">
      <h1>Hello, {name}!</h1>
      <p>You have {tasksToday} tasks today.</p>
      <p>That's {tasksToday * 25} minutes of focused work.</p>
    </main>
  );
}

Save. The browser updates by itself, without a reload. That's Vite's hot reload. Try changing the name and saving again.

For nicer styles, replace src/index.css with the course stylesheet. It only styles the To-Do app and isn't a React topic, so just copy it:

src/index.css
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: #f4f6f8; color: #1f2937; }
.app { max-width: 480px; margin: 48px auto; padding: 24px; background: white; border-radius: 16px; box-shadow: 0 4px 24px rgb(0 0 0 / 0.08); }
h1 { margin-top: 0; }
.task-form { display: flex; gap: 8px; }
.task-form input { flex: 1; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 16px; }
button { padding: 8px 14px; border: 0; border-radius: 8px; background: #10b981; color: white; font-size: 15px; cursor: pointer; }
.filters { display: flex; gap: 6px; margin: 16px 0; }
.filters button { background: #e5e7eb; color: #374151; }
.filters button.selected { background: #1f2937; color: white; }
.task-list { list-style: none; padding: 0; margin: 0; }
.task { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.task label { display: flex; gap: 10px; align-items: center; }
.task.done span { text-decoration: line-through; color: #9ca3af; }
.task button { background: transparent; color: #9ca3af; }
.empty, .count, .tip { color: #6b7280; }
.tip.error { color: #dc2626; }

The 6 JSX rules that trip up beginners

RuleWrongRight
Return one parent elementreturn <h1/><p/>return <><h1/><p/></>
Use className, not class<div class="app"><div className="app">
Close every tag<input> <br> <img src="a.png"><input /> <br /> <img src="a.png" />
JavaScript goes in { }<h1>name</h1><h1>{name}</h1>
Events are camelCase and take a functiononclick="save()"onClick={save}
Components start with a capital letter<taskItem /><TaskItem />

Commands you'll use

BunnpmWhat it does
bun create vite app --template react-tsnpm create vite@latest app -- --template react-tsCreate a React + TypeScript app
bun installnpm installInstall the packages
bun run devnpm run devRun the app with hot reload
bun run buildnpm run buildCheck types and build for the web (into dist/)
bun add <package>npm install <package>Add a package

Key takeaways

  • Vite creates and runs a React + TypeScript app in one command.
  • Your code lives in src/, starting from App.tsx.
  • JSX looks like HTML but follows a few JavaScript rules.
  • Curly braces drop any JavaScript value into the page.
  • Next: split the app into components and pass data with props.

Frequently asked questions

What is Vite?

Vite is the tool that runs your React app while you code (with instant updates when you save) and turns it into small, fast files for the web when you build it. It's the standard way to start a React project today.

Can I use npm instead of Bun?

Yes. Use npm create vite@latest todo-app -- --template react-ts, then npm install and npm run dev. Everything in the course works the same.

Why .tsx and not .jsx?

.tsx means TypeScript plus JSX. It's the same JSX you'd write in a .jsx file, with types on top so your editor catches mistakes like a misspelled prop.

Why className instead of class?

JSX becomes JavaScript, and class is a reserved word in JavaScript. So React uses className for CSS classes (and htmlFor instead of for on labels).

What is StrictMode?

A helper that only runs in development. It runs some code twice on purpose to help you spot bugs early. It does nothing in the finished app, so leave it on.

๐Ÿง  Quick check: setup and JSX

  1. 1. In which file do you write your app's main component?

  2. 2. How do you put a JavaScript value inside JSX?

  3. 3. Which is correct JSX?

  4. 4. A component returns two elements side by side. What do you wrap them in?

React for Beginners

Part 2 of 9: React Setup with Vite and Bun