React Foundations / Start Here

What is inside a React project

Lesson 3 of 35. Open to read. No account needed.

In the last lesson you created first-app, ran it and changed its heading. This lesson explains what happened in between: how a request for http://localhost:5173/ turns into React's output on the page, which files take part, and which ones you will edit. You need first-app from Set up Node.js and run your first React app.

The Files in first-app

Open the first-app folder in your editor. These are the files the template created and the ones npm install added:

File or folderWhat it isDo you edit it?
index.htmlThe page the browser loads first; it contains an empty element for React to fillRarely: the page title, perhaps
src/main.jsxThe entry point: starts React and tells it where to renderRarely
src/App.jsxThe top-level component: what the page showsConstantly
src/index.css, src/App.cssThe template's stylesWhen styling
src/assets/Images imported by componentsWhen adding images
public/Files served as they are, at the site's root address (for example /favicon.svg)Occasionally
package.jsonThe project's name, commands (scripts) and the packages it depends onWhen adding packages or commands
package-lock.jsonThe exact versions npm installedNever by hand; npm maintains it
node_modules/The installed packagesNever; recreate with npm install
vite.config.jsVite's settings for this projectRarely
.oxlintrc.jsonSettings for the template's code checkerReplaced later in the course
README.md, .gitignoreNotes from the template, and a list of files Git should ignoreNo

Files starting with a dot are hidden by default in macOS Finder and some editors. That does not matter here.

Most of your work will happen in src/. The rest of this lesson follows the four files that connect the browser to your component.

From Request to Page

Five numbered steps: the browser requests the address; index.html supplies an empty root element and a module script for src/main.jsx; main.jsx imports App and renders it into the root element; App.jsx defines the component; the page shows App's output inside the root element

How the browser gets from the address Vite printed to your component's output. Solid arrows show what loads or fills what; the dashed arrow is an import.

Follow the numbers:

  1. The browser asks the dev server for http://localhost:5173/.
  2. The server answers with index.html. The browser reads it, creates an empty <div id="root">, and finds a script it must load: /src/main.jsx.
  3. The browser asks for /src/main.jsx. That file is JSX, which browsers do not understand, so Vite converts it to plain JavaScript before sending it. The code imports App (step 4) and tells React to render it into the root element.
  4. src/App.jsx defines the App component, a function that returns what the page should show.
  5. React runs App and puts what it returns inside <div id="root">. That is what you see.

The arrow from index.html down to the page is the empty element; the arrow from main.jsx is React filling it. Everything React will ever show lives inside that one element.

index.html: the Shell

<!-- index.html (template) -->
<!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>first-app</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>

The first line is a comment naming the file; it is not in the real file.

Two lines matter:

  • <div id="root"></div> is empty on purpose. React fills it. The id is how main.jsx finds it.
  • <script type="module" src="/src/main.jsx"> loads the entry point. type="module" lets that file use import and export. The path starts with /, meaning "from the project's root folder" as the dev server sees it.

href="/favicon.svg" comes from the public/ folder, which the dev server serves at the site's root. In Vite projects index.html sits at the top of the project rather than in public/, because it is the starting point Vite reads.

src/main.jsx: Starting React

// src/main.jsx (template)
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>,
)

Read it in two parts.

The imports. StrictMode comes from the react package, and createRoot from react-dom/client. React is split in two: react holds what components are written with, and react-dom connects them to a browser page. The CSS import tells Vite to add those styles to the page. App is the default export of ./App.jsx; the ./ means "in the same folder as this file".

The call. Read it from the inside out:

  1. document.getElementById('root') is the standard browser function that finds the empty <div id="root"> from index.html.
  2. createRoot(...) creates a React root for that element: the place React manages from now on.
  3. .render(...) tells React what to display there. The argument is JSX, the HTML-like syntax that the next lessons teach: <App /> means "the App component".

<StrictMode> wraps the app in extra checks that run only in development. They make some mistakes visible early. For example, React renders components twice and runs some setup code twice so that code which is not repeatable stands out. You will see this when it matters, in How React renders. It has no effect on a production build. Leave it in.

This file rarely changes. Every lesson in the course keeps the same pattern: one root, filled by App.

src/App.jsx: Where Your Work Goes

App.jsx exports a function named App that returns JSX describing the page. The template's version contains images, a heading, a counter button and links. You changed its heading in the last lesson. A function like this, whose name starts with a capital letter and which returns JSX, is a component. The next lesson builds components from scratch, so this one only needs you to know where App comes from and where its output goes.

package.json: Scripts and Dependencies

These are the parts of first-app/package.json you will use:

  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "oxlint",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^19.3.1",
    "react-dom": "^19.3.1"
  },
  • scripts are named commands. npm run dev runs vite, the dev server. npm run build makes a production version, and npm run preview serves that version locally; both come at the end of the course. npm run lint runs the template's code checker, which a later lesson replaces.
  • dependencies are packages the app needs when it runs in the browser: React. devDependencies, further down the file, are tools used only while developing, such as Vite.
  • ^19.3.1 means "19.3.1 or any later 19.x version". A fresh npm install in a few months could therefore install a newer React. The package-lock.json file records exactly what was installed, so the same versions come back. The course's later projects list exact versions without ^, so that what you install matches what the lessons were checked with.

vite.config.js: the React Plugin

// vite.config.js (template)
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
})

Vite works with many frameworks. The React plugin adds what React needs: converting JSX in .jsx files and updating components in place when you save. Without it, Vite would not understand the JSX in main.jsx. You will not change this file in the course.

Exercise: Break the Connection on Purpose

The best way to see how these files depend on each other is to break the link between them and read the result.

Starting state: first-app from the previous lesson. In a terminal in react-foundations-practice/first-app, start the dev server with npm run dev and open the address it prints, with the browser's developer console open (F12, or Cmd+Option+I on macOS).

  1. In index.html, change <div id="root"></div> to <div id="app"></div>. Do not change main.jsx. Save.
  2. Look at the page and the console.

What happens: the page goes blank, and the console shows a red error whose message is:

Target container is not a DOM element.

The console usually also lists where the error came from; look for main.jsx in that list. document.getElementById('root') found nothing, because no element has that id any more, so it returned null. createRoot needs a real element (a DOM element) and refuses null. The message names the problem precisely once you know that "container" is the element you passed in.

  1. Change the id back to root and save. The page returns.

The general lesson: a blank page with a red console error is the start of a diagnosis, not the end. Read the message, then find the line it points to.

Your Turn: A Second Root

React can manage more than one root on a page. Try it, then decide why apps rarely do.

  1. In index.html, add <div id="banner"></div> just above the root div.
  2. In main.jsx, after the existing call, add a second call that renders a paragraph saying Separate root into the banner element.

Try it before reading the solution.

Solution

// Illustrative fragment: added at the end of src/main.jsx
createRoot(document.getElementById('banner')).render(<p>Separate root</p>)

The paragraph appears above the template's page. Each createRoot call gives React a separate area to manage. That is why apps normally have exactly one root. Two roots are two independent React apps: they cannot share state or pass data to each other through React. Use a second root only when React runs in a few separate places on a page that something else built. Remove the two additions before moving on, so first-app matches the template again.

Check Your Understanding

Put these in the order they happen, and say which file each belongs to:

  • React puts App's output on the page.
  • The browser loads the module script.
  • The browser receives the empty root element.
  • createRoot is called with the root element.
  • The App function runs.

Answer and Reasoning

  1. The browser receives the empty root element (index.html).
  2. The browser loads the module script (index.html names /src/main.jsx).
  3. createRoot is called with the root element (main.jsx).
  4. The App function runs (App.jsx, called by React after render).
  5. React puts App's output on the page (inside <div id="root">).

If you put App running before createRoot, look again at main.jsx: importing App only makes the function available. React calls it after render is asked to display <App />.

Reset and Clean Up

Make sure index.html has <div id="root"></div> again and that main.jsx matches the template. Stop the dev server with Ctrl+C. Keep first-app; Components and JSX uses it.

References

30 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy