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.
Contains the real DOM mount point and loads the JavaScript module entry.
Connects React DOM to the browser container and renders the application tree.
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:
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:
Extra warnings ยท developer tooling ยท fast iteration ยท hot updates.
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:
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:
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โ
- https://react.dev/learn/installation
- https://react.dev/blog/2025/02/14/sunsetting-create-react-app
- https://react.dev/reference/react-dom/client/createRoot
- https://vite.dev/guide/
Nextโ
Continue with Rendering a React application.