By WebNest Studio Engineering Team
React Tutorial
Setting Up a React Project
Before you can write a single component, you need a project scaffold: a folder structure, a build tool that turns JSX into browser-runnable JavaScript, and a local dev server with fast reload. For years the default answer was Create React App (CRA), but CRA is no longer actively maintained and is slow compared to modern alternatives. Today, Vite is the recommended way to start a new React project, and it is what you'll see in current documentation, tutorials, and most new codebases.
Why it matters
React code cannot run in a browser as written: JSX has to be compiled and the modules bundled. A build tool does that, and Vite is the standard choice for new projects. Being able to create a project, start the development server and find your way around the generated files is the first step of every React job.
Vite vs. Create React App
Vite uses native ES modules during development, so it starts a dev server almost instantly and updates the browser via Hot Module Replacement (HMR) in milliseconds, even in fairly large projects. Create React App, by contrast, bundles the entire app with Webpack before it can serve anything, which becomes noticeably slower to start and to reload as a project grows. CRA also stopped receiving meaningful updates, while Vite is actively developed and now the approach recommended in React's own documentation.
Creating a New Project with Vite
Run npm create vite@latest my-app -- --template react (or the TypeScript variant react-ts) in a terminal, then cd my-app, npm install, and npm run dev. This produces a working React app with a dev server running, typically at http://localhost:5173.
The Resulting Project Structure
A fresh Vite + React project includes a small, easy-to-read set of files and folders rather than the deeply nested configuration CRA used to generate.
index.html— the single real HTML file, at the project root, containing a<div id="root"></div>that React mounts into.src/main.jsx— the entry point that renders your root<App />component into that div.src/App.jsx— the starting component you edit first.package.json— lists dependencies and defines scripts likedev,build, andpreview.
Example
Scaffolding and running a new Vite + React project
# Terminal
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev
# Output in terminal:
# VITE v5.x.x ready in 320 ms
# ➜ Local: http://localhost:5173/
A dev server starts in a few hundred milliseconds. Opening http://localhost:5173 in a browser shows the default Vite + React starter page with a spinning logo and a counter button. Editing src/App.jsx and saving updates the page in the browser almost instantly, without a full reload.
Common Mistakes
- Starting a brand-new project with "npx create-react-app" out of habit, without realizing it is effectively unmaintained and noticeably slower than Vite for both startup and rebuilds.
- Forgetting to run "npm install" after scaffolding the project, then getting confusing "module not found" errors when running "npm run dev".
- Editing index.html expecting to see UI changes, when the actual UI comes from the React component tree rendered into the single <div id="root"> — index.html itself rarely needs edits.
- Confusing the dev server (npm run dev, for local development with hot reload) with the production build (npm run build, which outputs static optimized files meant for deployment).
Exercise
In a terminal, with Node.js installed, write the commands to create a new React project named my-app with Vite, install its dependencies and start the development server. Then replace the contents of src/App.jsx with a component that shows a heading.
Expected result: the browser shows the heading "Hello from React" at the local address printed by the dev server, and the page updates when the file is saved.
# TODO: create the project with Vite's react template
# TODO: go into the folder and install the dependencies
# TODO: start the development server
// src/App.jsx
// TODO: export a component that renders an h1
Show hints
- The project is created with
npm create vite@latest my-app -- --template react. - A component is a function that returns JSX, exported as the default export of the file.
Show solution
npm create vite@latest my-app -- --template react
cd my-app
npm install
npm run dev
// src/App.jsx
export default function App() {
return <h1>Hello from React</h1>;
}
Quick quiz
1. Which tool is the usual choice for starting a new React project today?
- A. Create React App
- B. Vite
- C. Grunt
- D. Bower
Show answer
B. Create React App is no longer maintained; Vite starts faster and is actively developed.
2. Which command starts the development server in a Vite project?
- A. npm run dev
- B. npm start server
- C. vite build
- D. npm install
Show answer
A. npm run build creates the production files, and npm run preview serves them locally.
3. In a Vite React project, which file mounts the application into the page?
- A. package.json
- B. vite.config.js
- C. src/App.css
- D. src/main.jsx
Show answer
D. It calls createRoot on the element with the id root and renders the App component.
Interview questions
What is React?
Show answer
React is a JavaScript library for building user interfaces from components. A component is a function that returns a description of what should be on screen for the current data. When the data changes, React works out the difference and updates the DOM. It handles the view only; routing, data fetching and global state come from other libraries or from a framework such as Next.js.
Why does a React project need a build tool?
Show answer
Browsers do not understand JSX, so it must be compiled into JavaScript function calls. A build tool also resolves imports of packages from node_modules, bundles and minifies the code for production, handles CSS and images, and provides a development server that updates the page instantly when a file changes. Vite does all of this with almost no configuration.
Key Points to Remember
- Vite is the modern, recommended way to start a React project; Create React App is legacy and no longer actively maintained.
- "npm create vite@latest" scaffolds a project; "npm install" then "npm run dev" gets it running locally.
- A Vite React project centers on index.html, src/main.jsx (entry point), and src/App.jsx (root component).
- Vite's speed comes from serving native ES modules directly during development instead of bundling everything upfront.
Practice in the playground
Write and run your own code for this topic, or start from the exercise or an example. Shows a live preview of plain HTML, CSS and JavaScript. JSX needs a React project on your computer. Your code for each topic is kept in this browser.
Run the examples
Change an input, predict the result, then compare it with the output. Explain why the result changes.
These examples need a project environment on your computer, so they can be copied but not run here. Codelab runs Python, FastAPI backends with SQLite, plain Java 17 and HTML/CSS/JavaScript.
Written by
WebNest Studio Engineering Team
Practical lessons from developers working with Java, Python, React, databases and production systems.
Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering