Setting up a React project
Start a React project with Vite or a framework, learn what each file in a new project does, how createRoot and StrictMode start it, and use React DevTools.
- 01Start a project the right wayChoose between a framework and Vite the way React's documentation advises, and create a Vite project with React.
- 02Find your way around itSay what index.html, main.jsx, App.jsx, package.json, and vite.config.js each do, and which one loads which.
- 03Explain how React startsRead the entry file: createRoot takes over one element, render shows App in it, and StrictMode adds checks while you develop.
- 04Inspect componentsInstall React DevTools and use it to see your component tree, props, and state.
From an empty folder to React in the browser
So far you've run React inside this page. To build your own app, you need a project: a folder with your components, the packages they use, and a tool that turns them into a page a browser can open. One command makes that folder for you. When you start it, the browser shows a small counter. Here is that counter's component, cut down to the parts that run (the real file also shows three images and a few links). Click the button in the result.
import { useState } from 'react' function App() { const [count, setCount] = useState(0) return ( <section id="center"> <h1>Get started</h1> <p> Edit <code>src/App.jsx</code> and save to test <code>HMR</code> </p> <button type="button" className="counter" onClick={() => setCount((count) => count + 1)} > Count is {count} </button> </section> )} export default AppLine 1 imports useState from the react package. Lines 3 to 21 are the component, a function named App. Line 4 gives it a number to remember, count, starting at 0 (this is state; you met it in Why React?). Lines 6 to 20 describe the screen: a heading, a sentence, and a button. Line 15 runs when you click the button and asks React for the next number, so line 17 shows Count is 1, then 2. Line 23 exports App so another file can use it.
Now press Edit & run, click the button a few times, and change Get started on line 8 to Tip calculator. The result shows the new heading a moment later. On this page each change runs the example again, so the count goes back to 0. In your own project it's better: when you save App.jsx, the browser updates the heading and keeps the count. That's the HMR on line 10: hot module replacement, swapping one changed file into the running page without reloading it.
src. npm run dev starts Vite, which turns your JSX into JavaScript and serves the page at localhost:5173. Save a file, and the page in the browser updates.A meal kit arrives with the ingredients measured and labelled, and a card saying what's inside. You still cook, and you can swap any ingredient for your own. You taste as you go, and the dish changes as you cook.
- In real life: The box arrives with every packet labelled
- In React: One command copies a template: index.html, src/main.jsx, src/App.jsx, …
- In real life: The list of what's in the box
- In React: package.json, the list of packages and commands
- In real life: The stove you cook on
- In React: Vite's development server, started with npm run dev
- In real life: Tasting as you cook
- In React: Saving a file and seeing the page update
- In real life: Your own dish, cooked from the kit
- In React: Your app, written in App.jsx and the components it uses
A React project is a folder of files and the tools that run them. A build tool like Vite, or a framework like Next.js, makes the folder in one command and serves your app while you work. One file, main.jsx, hands React an element on the page with createRoot; from there, everything is your components.
Vite or a framework
There are two kinds of tools for starting a React project, and React's own documentation, react.dev, names both. This is what its Creating a React App page says, as checked in October 2026:
- For a new app or website, start with a framework. A framework is React plus the parts a whole app needs: page addresses (which page shows for
/cart), loading data, and the build. The page recommends Next.js (its App Router), React Router, and Expo for phone apps, and lists TanStack Start and RedwoodSDK as newer options. - To learn React, or when no framework fits, build from scratch with a build tool such as Vite, Parcel, or Rsbuild. You get React and a development server, and you choose everything else yourself.
Each recommended framework starts with one command:
npx create-next-app@latest
npx create-react-router@latest
npx create-expo-app@latestLine 1 makes a Next.js project, line 2 a React Router project, and line 3 an Expo project for phone and web apps. npx runs a package's command without installing it first, and @latest asks for its newest version. Each one asks a few questions, then makes a folder. Frameworks don't need a server of their own, either: react.dev notes they can also build a plain app that runs only in the browser.
How to read the table: each row asks the same question of a Vite project and a framework project.
| Question | Vite, from scratch | A framework |
|---|---|---|
| What do you get? | A development server and a build. React shows your components; everything else is your choice. | React, plus page addresses, data loading, and rendering on the server, already wired together. |
| Who calls createRoot? | You do, in src/main.jsx. You can read every line. | The framework does it for you, so most apps never see that file. |
| What does React's documentation say? | Use it to learn React, or when no framework fits your app. | Start a new app with one of these. |
| Good for | Learning, small apps that run in the browser, and adding React to a page. | Most real apps with many pages, like a shop or a dashboard. |
This course uses Vite. It's the smallest setup that is still a real project, and you see every file, including the one that starts React. A framework hides that file and calls createRoot for you, which is handy in an app and confusing while you learn. The React frameworks lesson covers them once you know React itself.
Older tutorials start with npx create-react-app. React deprecated Create React App in February 2025, and react.dev says not to use it for new apps. If you meet a project made with it, it still runs; react.dev's Sunsetting Create React App post explains how to move it to Vite or a framework.
Creating a project with Vite
You need Node.js, the program that runs JavaScript outside the browser, and npm, which comes with it (the Setting up your tools lesson installs both). Then open a terminal in the folder where you keep projects and run these four commands:
npm create vite@latest tip-calculator -- --template react
cd tip-calculator
npm install
npm run dev- Line 1 runs
create-vite, Vite's project maker.tip-calculatoris the new folder's name. The--passes what comes after it tocreate-viteinstead of npm, and--template reactpicks React with JavaScript. - Line 2 moves the terminal into the new folder.
- Line 3 downloads the packages listed in
package.jsoninto a folder callednode_modules(the npm & package.json lesson explains how). - Line 4 starts Vite's development server: a small web server on your computer that serves the project while you work.
Line 1 still asks a couple of questions in the terminal. Run npm create vite@latest with nothing after it, and it asks every question, one at a time. How to read the table: the left column is the question, the right column is what to pick for this course.
| The question | What to pick, and why |
|---|---|
| Project name | tip-calculator. It becomes the folder's name. Giving it in the command skips this question. |
| Select a framework | React. The list also has Vue, Svelte, and others, because Vite isn't only for React. |
| Select a variant | JavaScript, for now. The list also has TypeScript, versions with the React Compiler, and frameworks such as React Router. |
| Which linter to use? | Oxlint, the first choice, or ESLint. A linter reads your code and warns about likely mistakes. |
| Install with npm and start now? | Yes runs npm install and npm run dev for you. No prints them, so you can run them yourself. |
When the server is running, the terminal shows something like this:
VITE v8.3.5 ready in 312 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show helpLine 1 names the Vite version and how long it took to start. Line 3 is the address to open: http://localhost:5173/. localhost means "this computer", and 5173 is the port Vite picks when it's free. Line 4 says the app is only reachable from your own computer. The server keeps running until you press Ctrl + C in the terminal.
create-vite 9.3.1 makes projects with Vite 8 (the newest release was 8.3.5), @vitejs/plugin-react 6.1.2, and React 19.3.1, the version this course's examples run (they run React 19.3.1). Vite needs Node.js 20.19 or 22.12 or newer. Node.js 20 reached its end of life in April 2026, so install the LTS (long-term support) version that nodejs.org offers: Node.js 24 or newer. Tools change quickly: if your questions or files look a little different, check Vite's Getting Started guide.
What's in a new project
Here is the new folder, after npm install:
tip-calculator/
├── node_modules/ (made by npm install)
├── public/
│ ├── favicon.svg
│ └── icons.svg
├── src/
│ ├── assets/
│ │ ├── hero.png
│ │ ├── react.svg
│ │ └── vite.svg
│ ├── App.css
│ ├── App.jsx
│ ├── index.css
│ └── main.jsx
├── .gitignore
├── .oxlintrc.json
├── index.html
├── package-lock.json (made by npm install)
├── package.json
├── README.md
└── vite.config.jssrcis your code.App.jsxis where you write the app, andmain.jsxstarts it.index.cssstyles the whole page, andApp.cssstyles the starter.src/assetsholds images your code imports.publicholds files served as they are, at the top of the site:public/favicon.svgis the tab icon, at/favicon.svg..gitignorelists what Git, the version-control tool, should skip, likenode_modules..oxlintrc.jsonsets up Oxlint, the linter you picked.
Three files at the top hold the setup. First, package.json:
{ "name": "tip-calculator", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", "build": "vite build", "lint": "oxlint", "preview": "vite preview" }, "dependencies": { "react": "^19.3.1", "react-dom": "^19.3.1" }, "devDependencies": { "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@vitejs/plugin-react": "^6.1.2", "oxlint": "^1.88.0", "vite": "^8.3.4" }}Line 2 is the project's name. Line 5, "type": "module", says the JavaScript files use import and export. Lines 6 to 11 are the scripts: npm run dev runs line 7, vite. Lines 12 to 15 are the packages your app runs with: react and react-dom. The ^ in ^19.3.1 means "19.3.1 or a newer 19 release". Lines 16 to 22 are tools you only need while building the app: Vite, its React plugin, Oxlint, and type information for editors.
Next, the page itself:
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>tip-calculator</title> </head> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body></html>In a Vite project, index.html sits at the top of the folder, not in public. It's the page the browser opens. Its <body> holds only two things: line 10, an empty <div id="root">, and line 11, a <script type="module"> that loads src/main.jsx. create-vite put the project's name into the <title> on line 7.
index.html. Its <script> loads src/main.jsx, which imports App, hands React the empty <div id="root">, and asks it to show App there.Last, Vite's settings:
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})Line 1 imports Vite's React plugin, and line 6 turns it on. The plugin sets up how your JSX becomes JavaScript, and adds Fast Refresh, the part of hot module replacement that keeps a component's state when you save its file. You'll rarely change this file. The Bundlers & build tools lesson shows what Vite does with your files.
Use the playground to go through the files in the order things happen: npm reads package.json, the browser opens index.html, which loads main.jsx, which imports App.jsx. Each button shows the real file, what reads it, and how often you'll edit it.
{
"name": "tip-calculator",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "oxlint",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@vitejs/plugin-react": "^6.1.2",
"oxlint": "^1.88.0",
"vite": "^8.3.4"
}
}- What reads it
- npm, when you install packages or run a script.
- How often you edit it
- Sometimes
The project's list of packages and commands. npm install reads it, and npm run dev runs its dev script.
createRoot and StrictMode: where React starts
Why React? showed this file briefly, and How React works: a first look mentioned StrictMode's second call. Here is the file as the template makes it, src/main.jsx:
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
)- Line 1 imports
StrictModefromreact, the package every React app shares. - Line 2 imports
createRootfromreact-dom/client, the part of React that draws to a web page in the browser. - Line 3 imports a CSS file. That isn't JavaScript: Vite sees the import and adds the styles to the page.
- Line 4 imports your
Appcomponent fromApp.jsx. - Line 6 finds the empty
<div id="root">fromindex.htmland gives it tocreateRoot, which makes a root: React takes over everything inside that element. Then.render(…)tells React what to show there. - Lines 7 to 9 are what it shows:
<App />, wrapped in<StrictMode>.
Most apps have exactly one createRoot call, and you write it once and leave it. The first time render runs, React clears anything already inside the element. From then on, you never touch the page yourself: your components describe it.
Here is the same file, live. The preview on this page links CSS files from the page instead, so this copy leaves out line 3. Its App.jsx tab holds a component that prints a line to the console each time React calls it:
import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import App from './App.jsx' createRoot(document.getElementById('root')).render( <StrictMode> <App /> </StrictMode>,)The result shows the heading, and the console under it shows Rendering App with a small 2 beside it: the line was printed twice. That's StrictMode. In development, it makes React call each component a second time, to catch components that do something they shouldn't while being called. A component that only works out what to show gives the same answer both times, so you see no difference on the page.
Press Edit & run and try two changes, one at a time, pressing Reset in between:
- Delete line 6 and line 8, so line 7 is just
<App />. The console showsRendering Apponce, with no2. - Change
'root'on line 5 to'app'. The page has no element with that id, sogetElementByIdgivesnull, and the result shows React's error:Target container is not a DOM element.
StrictMode makes React call App a second time, so its log prints twice. The production build calls it once. The page shows the same thing either way.StrictMode's checks, as react.dev lists them, all in development only:
- React calls your components an extra time, to find rendering that isn't pure.
- React runs Effects an extra time, to find Effects that don't clean up after themselves.
- React runs ref callbacks an extra time, to find refs that don't clean up.
- React warns when your code uses old APIs that are going away.
Effects and refs come later in the course; for now, remember that StrictMode only adds checks, and the production build made by npm run build leaves them all out. Keep it: react.dev recommends wrapping the whole app in it. You'll learn what "pure" means, and why the double call finds bugs, in Keeping components pure.
createRoot is defined in ReactDOMRoot.js, line 171, at React 19.3.1. The first thing it does is check that it got a real element. The rest makes the objects React keeps for the root, which Fiber: React's unit of work, in the Under the hood stage, explains.
export function createRoot(
container: Element | Document | DocumentFragment,
options?: CreateRootOptions,
): RootType {
if (!isValidContainer(container)) {
throw new Error('Target container is not a DOM element.');
}React's code adds type notes, like : Element, which you can read past. Lines 5 to 7 are the check: when container isn't an element, such as the null from a wrong id, line 6 throws the error you saw.
Seeing your components with React DevTools
The browser's developer tools show the page's elements: <div>, <button>, and so on (the Debugging in the browser lesson tours them). They don't show your components. React DevTools does. It's a free browser extension, made by the React team, for Chrome, Firefox, and Edge. Install it once, and it works on every React page you open.
Then open a React page, like your project at localhost:5173, and open the developer tools. Two new tabs appear: Components and Profiler. To try them, put this in your project's App.jsx. Here it runs live, so you can see what it does first:
import { useState } from 'react' function ProductCard({ name, price, onAdd }) { return ( <p> {name}: ${price} <button onClick={onAdd}>Add</button> </p> )} export default function App() { const [count, setCount] = useState(0) return ( <> <h2>In cart: {count}</h2> <ProductCard name="Tea" price={3} onAdd={() => setCount(count + 1)} /> <ProductCard name="Cake" price={4} onAdd={() => setCount(count + 1)} /> </> )}Lines 3 to 9 are a ProductCard component that shows a name, a price, and an Add button. Lines 11 to 21 are App: line 12 keeps a count in state, line 16 shows it, and lines 17 and 18 use ProductCard twice, with different props. Click Add on either card and the count goes up.
App, and the two ProductCard components inside it. Select the second one, and the panel lists its props, name: "Cake" and price: 4, and says App rendered it.In the Components tab, the tree shows App and its two ProductCard components. Select the second card: the panel beside the tree shows its props, name: "Cake" and price: 4. Select App, and under hooks it shows its state, State: 0. Click Add on the page twice and the panel says State: 2. You can also change a value in the panel, and the page follows.
How to read the table: each row is one part of React DevTools, what it shows, and when you'd use it.
| Part | What it shows | When you use it |
|---|---|---|
| Components | Your component tree, as React sees it: App and the components inside it. | To find a component and check what it got. |
| The panel beside the tree | The selected component's props, its state (listed under hooks), and what rendered it. | To see why a component shows what it shows. You can edit the values to try things. |
| Profiler | A recording of each render: which components rendered and how long they took. | To find slow parts. The Profiling React apps lesson covers it. |
For Safari and other browsers without the extension, react.dev gives a separate app. Install it, start it, and it prints a <script> tag to add to the top of your page's <head>:
npm install -g react-devtools
react-devtoolsLine 1 installs the react-devtools package for your whole computer (-g), not into one project. Line 2 opens its window. React DevTools also makes StrictMode's second call easier to read: react.dev notes that, with it installed, logs from the second call appear slightly dimmed in the console.
Your first changes to a new project
The starter is there to prove everything works. Once you've seen the counter, make the project yours. In the next lesson you'll build a tip calculator, and it starts like this:
- Replace everything in
src/App.jsxwith your own component. - Delete
src/App.cssand the images insrc/assetsif nothing imports them. Emptysrc/index.css, or keep it for styles the whole page shares. - Leave
main.jsx,index.html, andvite.config.jsas they are.
export default function App() { return ( <main> <h1>Tip calculator</h1> <p>Work out the tip and split the bill.</p> </main> )}Line 1 exports the component as the file's default, the one main.jsx imports, in a shorter way than the starter: on the same line as the function. Lines 3 to 6 describe a <main> with a heading and one sentence. The styles.css tab stands in for index.css: this page links it for you, where your project imports it in main.jsx.
Each script in package.json has its moment. How to read the table: the first column is what you type, then what it does, then when you use it.
| You type | What it does | When you use it |
|---|---|---|
npm run dev | Starts Vite's development server at http://localhost:5173. | While you work. Every save updates the page. |
npm run build | Writes small, fast files for real visitors into a dist folder. | When you're ready to put the app online. |
npm run preview | Serves the dist folder on your computer. | To check the built app before you upload it. |
npm run lint | Runs Oxlint on your code. | To catch likely mistakes, such as breaking the rules of hooks. |
Every tool in the project has its own job, and knowing which does what helps when something goes wrong. Sort each job:
- Turns the JSX in App.jsx into plain JavaScript
- Updates the page when a component's state changes
- Decides which page shows for the address /cart
- Serves your files at http://localhost:5173
- Gives a component a value it remembers, with useState
- Loads a page's data on the server before sending it
- Writes the dist folder for real visitors
- Calls your component twice in development to find mistakes
Sort each job by what does it in a React project: React itself, the build tool (Vite), or a framework like Next.js.
Common mix-ups
- "Start with Create React App." No. It was deprecated in February 2025. Start with a framework, or with Vite to learn.
- "Vite is a React framework." No. It's a build tool: a development server and a build. It works with Vue, Svelte, plain JavaScript, and more. It doesn't add page addresses or server rendering.
- "StrictMode calls my components twice for my users too." No. The extra calls happen only in development. The production build calls each component once.
- "StrictMode changes what my app shows." No. It only adds checks. If the page looks different with it, a component is doing something while rendering that it shouldn't.
- "React makes the root element." No.
index.htmlhas it, andmain.jsxmust find it by the same id. A wrong id givesnull, andcreateRootthrows. - "React DevTools is a package in my project." No. It's a browser extension. The
react-devtoolsnpm package is a separate app, for browsers without the extension. - "The browser runs my JSX files." No. Browsers can't read JSX. Vite turns each file into plain JavaScript before the browser gets it.
Practice exercises
Most exercises show their result under the code. Press Edit & run to change the code and watch the result, and its console, update.
This is a project's main.jsx, and its App logs Rendering App each time it's called. In development, how many times is that line printed when the page loads? Answer first, then press Edit & run: the console shows the line once, with the number of times beside it.
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
)import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import App from './App.jsx' createRoot(document.getElementById('root')).render( <StrictMode> <App /> </StrictMode>,)App prints each time React calls it. StrictMode, on lines 6 to 8, makes React call it twice in development, so Rendering App appears twice. A production build would print it once.
This main.jsx looks for the wrong element. Press Edit & run: the result shows an error instead of the app. Read it, then fix line 5. Once it works, what heading does the result show?
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('app')).render(
<StrictMode>
<App />
</StrictMode>,
)import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import App from './App.jsx' createRoot(document.getElementById('root')).render( <StrictMode> <App /> </StrictMode>,)getElementById('app') found nothing and gave null, so createRoot threw. With 'root', it gets the real <div>, and React shows App in it: the heading Tip calculator.
Add a Reset button under the counter that sets the count back to 0. Click the counter three times, then Reset. What does the counter button say?
import { useState } from 'react' function App() { const [count, setCount] = useState(0) return ( <section id="center"> <h1>Get started</h1> <p> Edit <code>src/App.jsx</code> and save to test <code>HMR</code> </p> <button type="button" className="counter" onClick={() => setCount((count) => count + 1)} > Count is {count} </button> </section> )} export default Appimport { useState } from 'react' function App() { const [count, setCount] = useState(0) return ( <section id="center"> <h1>Get started</h1> <p> Edit <code>src/App.jsx</code> and save to test <code>HMR</code> </p> <button type="button" className="counter" onClick={() => setCount((count) => count + 1)} > Count is {count} </button> <button type="button" onClick={() => setCount(0)}> Reset </button> </section> )} export default AppThe new button on lines 19 to 21 calls setCount(0). React calls App again with count at 0, and the first button says Count is 0.
Which command makes the small, fast files you upload so real visitors can use your app?
{
"name": "tip-calculator",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "oxlint",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@vitejs/plugin-react": "^6.1.2",
"oxlint": "^1.88.0",
"vite": "^8.3.4"
}
}{
"name": "tip-calculator",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "oxlint",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@vitejs/plugin-react": "^6.1.2",
"oxlint": "^1.88.0",
"vite": "^8.3.4"
}
}Line 8 names the build script, which runs vite build. You run it with npm run build, and it writes the files for real visitors into dist. npm run dev is only for working on your own computer.
This shop page already exists, and React shows only the cart badge in its header. Add a second root that shows the Reviews component in the empty <div id="reviews">. What does it show under the product?
import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import CartBadge from './CartBadge.jsx'import Reviews from './Reviews.jsx' createRoot(document.getElementById('cart-badge')).render( <StrictMode> <CartBadge /> </StrictMode>,)import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import CartBadge from './CartBadge.jsx'import Reviews from './Reviews.jsx' createRoot(document.getElementById('cart-badge')).render( <StrictMode> <CartBadge /> </StrictMode>,) createRoot(document.getElementById('reviews')).render( <StrictMode> <Reviews /> </StrictMode>,)A page can have more than one root. Each createRoot takes over its own element: the badge in the header, and now the reviews under the product. The rest of the page stays plain HTML. react.dev mentions this for adding React to parts of an existing page.
The result shows a number this one-order component shouldn't. What number does it show, and why? Then change the code so it shows 1 even with StrictMode on.
const orders = [] export default function OrderCount() { orders.push('Tea') return <p>Orders: {orders.length}</p>}export default function OrderCount() { const orders = ['Tea'] return <p>Orders: {orders.length}</p>}Line 4 changed an array outside the component each time React called it, so StrictMode's second call left two orders. A component should only work out what to show, and give the same answer every time. With the array made inside, every call shows Orders: 1. Keeping components pure explains this properly.
Check your understanding
For each question, think about which file or tool is doing the work. Press Edit & run on a question's code to check.
Question 1 of 7You're starting a new online shop with many pages. What does React's documentation suggest?
Choose an answer to see the explanation.
Question 2 of 7In
npm create vite@latest tip-calculator -- --template react, what does the--do?Choose an answer to see the explanation.
Question 3 of 7You open http://localhost:5173. Which file of the project does the browser load first?
Choose an answer to see the explanation.
Question 4 of 7How many times does this code print
Rendering Greetingwhen the page first loads in development?Read the code, then predictimport { StrictMode } from 'react' import { createRoot } from 'react-dom/client' function Greeting() { console.log('Rendering Greeting') return <h1>Hello</h1> } createRoot(document.getElementById('root')).render( <StrictMode> <Greeting /> </StrictMode>, )Choose an answer to see the explanation.
Question 5 of 7What does StrictMode do for visitors using your built app (
npm run build)?Choose an answer to see the explanation.
Question 6 of 7index.html has
<div id="root">, but main.jsx callscreateRoot(document.getElementById('app')). What happens?Choose an answer to see the explanation.
Question 7 of 7Where do you get React DevTools for Chrome?
Choose an answer to see the explanation.
Key takeaways
- React's documentation recommends a framework, like Next.js or React Router, for a new app, and a build tool like Vite to learn React or when no framework fits.
npm create vite@latest tip-calculator -- --template reactmakes a project;npm installgets its packages;npm run devserves it atlocalhost:5173and updates the page as you save.- The browser opens
index.html, which loadssrc/main.jsx, which importsAppfromsrc/App.jsx. createRoottakes over one element, usually<div id="root">, andrendershows your app inside it.- StrictMode calls your components twice and adds other checks, only in development, to find mistakes early. It changes nothing for your users.
- React DevTools is a browser extension that shows your component tree, with each component's props and state.
Remember the one-liner.
One command makes the project; index.html loads main.jsx; createRoot hands React the root; you write the components.
Coming next: Your first React app. You'll build a small tip calculator in this project, one step at a time: components, data, a click, and state.