Skip to main content

Set up React with Vite

For a small client-side React application where you are learning React itself, Vite is a practical modern build-tool choice.

This chapter is about the tooling around React. Vite is not part of React core.

Why not start with Create React App?โ€‹

Create React App played an important historical role, but React officially deprecated it for new apps in 2025. Modern projects should use a framework when the application benefits from one, or use a build tool such as Vite when building a client-side React application from scratch.

For this handbook, Vite keeps the environment small enough that you can see React itself clearly.

Create a projectโ€‹

With a current Node.js installation:

npm create vite@latest

Choose a React template, then install dependencies and start development:

cd my-react-app
npm install
npm run dev

Vite prints the local development URL in the terminal.

Typical project structureโ€‹

A small Vite React project commonly looks like this:

my-react-app/
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ App.jsx
โ”‚ โ”œโ”€โ”€ main.jsx
โ”‚ โ””โ”€โ”€ index.css
โ””โ”€โ”€ vite.config.js # when project-specific config is needed

The exact generated files can change between Vite versions. Learn the responsibilities, not the filename trivia.

Vite React project responsibilitiesThe useful model is what each layer owns, not memorising template filenames.
Browser entryindex.html

Contains the real DOM mount point and loads the JavaScript module entry.

React entrysrc/main.jsx

Connects React DOM to the browser container and renders the application tree.

Application UIsrc/App.jsx

Defines the top-level component and composes the rest of the React tree.

index.htmlโ€‹

Unlike older setups that hide the HTML template behind tooling, Vite keeps index.html visible at the project root.

A simplified version contains a root element:

<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>

The browser has a real DOM node named root. React will manage the React tree mounted inside that node.

main.jsxโ€‹

The entry file connects React to the browser DOM.

import {StrictMode} from 'react';
import {createRoot} from 'react-dom/client';
import App from './App.jsx';

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

Mental model:

How a Vite React app reaches the pageThe browser mount point exists first; React then owns the tree inside it.
index.html
The browser loads the document and module entry.
#root DOM node
A real browser element becomes the mount container.
React root
React DOM creates the root that manages this container.
Component tree
App and its descendants become the React tree managed inside the root.

Most application components never call createRoot. It is normally used at the application entry point.

App.jsxโ€‹

App is an ordinary React component:

export default function App() {
return (
<main>
<h1>My React app</h1>
</main>
);
}

There is nothing special about the name App. It is simply a conventional top-level component name.

Development server vs production buildโ€‹

During development:

npm run dev

You get fast feedback, development warnings, and hot updates from Vite.

For a production build:

npm run build

Vite creates optimized output for deployment.

A useful distinction:

Development vs productionMeasure and debug with the environment distinction in mind.
DevelopmentOptimised for feedback

Extra warnings ยท developer tooling ยท fast iteration ยท hot updates.

ProductionOptimised for delivery

Optimized output ยท deployable assets ยท no development-only checks.

Do not make performance conclusions from development mode alone.

React DevToolsโ€‹

Install React DevTools in a supported browser while learning and debugging React.

Use it to inspect:

  • component trees;
  • props;
  • state;
  • Context;
  • rendering/profiling behavior.

DevTools is not a substitute for understanding the render model, but it makes that model visible.

JavaScript or TypeScript template?โ€‹

Both are valid.

If you are learning React fundamentals for the first time, JavaScript can reduce the number of concepts introduced at once. If you already know TypeScript, using the TypeScript template is reasonable.

The React mental model is the same either way.

Should every React app use Vite?โ€‹

No.

Use a framework when you need framework-level capabilities such as integrated routing, data loading, server rendering, React Server Components infrastructure, or application conventions that the framework provides.

Use a client build tool when you intentionally want a client-rendered React application or need control over your own architecture.

Decision model:

Which starting point fits the application?
Learning React fundamentals or intentionally building a client-rendered appVite is a strong build-tool choice.
Need integrated routing, server rendering, data loading, RSC, or deployment conventionsEvaluate a React framework.
Unsure which capability you actually needClassify the application requirements before choosing tooling.

Do not confuse "React" with whichever tool created the project.

Common mistakesโ€‹

Learning generated files instead of responsibilitiesโ€‹

Templates evolve. Understand entry points, modules, and root rendering.

Editing node_modulesโ€‹

Dependencies under node_modules are installed artifacts, not application source code.

Treating build-tool environment variables as secret storageโ€‹

Frontend values shipped to the browser can be inspected by users. Do not put server secrets into client bundles.

Assuming Vite supplies React featuresโ€‹

Hooks, components, Suspense, Context, and rendering are React. The dev server and build pipeline are tooling.

Exerciseโ€‹

Create a Vite React project and make the component tree:

Exercise component tree
App
Header
ProductList
Contains multiple ProductCard children.
Footer

Requirements:

  • each component should be a function component;
  • move each major component into its own module;
  • pass product data through props;
  • do not add state yet.

Interview questionsโ€‹

Juniorโ€‹

What is the responsibility of createRoot?

Mid-levelโ€‹

What is the difference between React and Vite?

Seniorโ€‹

When would you choose a framework instead of a client build tool for a new React application?

Referencesโ€‹

Nextโ€‹

Continue with Rendering a React application.