Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

Why React, JSX and Components: The Page as a Function of Data

The same task card built twice: by hand with the DOM, and as a React component. See what JSX compiles to, why a component is just a function, the four JSX rules with their real compiler errors, and how createRoot puts the tree on the page.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Explain why describing the page beats changing it step by step
  • Read what JSX compiles to and what a React element really is
  • Write a component as a function: props in, JSX out
  • Follow the four JSX rules and mount an app with createRoot

Before you start

  • Basic HTML and CSS
  • JavaScript functions, objects and the ternary operator

A small page shows three task cards. One of them, Email Jack, owned by Olivia, has a yellow badge that says To do. Then Jack gets his email, and the badge has to turn green and say Done. How does the page find out?

There are two answers. You can change the page yourself, one step at a time. Or you can describe what the page should look like for any data, and let React work out the steps. This article builds the same card both ways, then opens up JSX and components to show what is going on inside. Every output below comes from running the lecture's project.

Two ways to change a page

By hand versus page as a function of data By hand (plain DOM) 1. find the badge 2. set its class: badge done 3. set its text: Done every step must match the page With React data: done false → true React runs TaskCard(props) again page shows Done page = f(data)
By hand you write every step of every change. With React you describe the page for the data, and React does the steps.

Building and changing a card by hand

Here is app.js with no framework at all. addCard creates a div, an h3, a p and a span, fills each one, and hangs them on the page. markDone then changes one card later.

// Plain DOM: build and change every element by hand
const app = document.getElementById("app");

function addCard(title, owner, done) {
  const card = document.createElement("div");
  card.className = "card";
  const h3 = document.createElement("h3");
  h3.textContent = title;
  const p = document.createElement("p");
  p.textContent = "Owner: " + owner;
  const badge = document.createElement("span");
  badge.className = done ? "badge done" : "badge";
  badge.textContent = done ? "Done" : "To do";
  card.append(h3, p, badge);
  app.append(card);
  return card;
}

addCard("Write report", "Emma", true);
const jack = addCard("Email Jack", "Olivia", false);
addCard("Book flights", "Lucas", false);
console.log("before:", jack.lastChild.outerHTML);

// A change, by hand: find each piece, fix it
function markDone(card) {
  const badge = card.querySelector(".badge");
  badge.className = "badge done";
  badge.textContent = "Done";
}

markDone(jack);
console.log("after: ", jack.lastChild.outerHTML);

The console shows the badge before and after the change:

before: <span class="badge">To do</span>
after:  <span class="badge done">Done</span>

That is twelve lines of steps for one card, and we haven't changed anything yet. Notice also that we had to keep jack around, the card element itself, only so we could find it again later.

Now the trap. Delete line 27, the className line, and run it again:

BREAK IT, no className line:
before: <span class="badge">To do</span>
after:  <span class="badge">Done</span>

The badge says Done but keeps the yellow To do style. The text and the style disagree, and nothing warns you. Every change by hand is a list of steps, and every step has to match what the page already shows. That is the problem React solves.

What JSX really is

React components are written in JSX, the HTML-like syntax in .tsx files. Here is a small demo file:

// What JSX makes (see it compiled: npm run compile)
import TaskCard from '../src/TaskCard'

const title = <h3 className="title">Write report</h3>
const card = (
  <TaskCard title="Email Jack" owner="Olivia"
    done={false} />
)

console.log('title.type: ', title.type)
console.log('title.props:', title.props)
console.log('card.type:  ', card.type)
console.log('card.props: ', card.props)

The line <h3 className="title">Write report</h3> has three parts: the tag name h3 is the type, the attribute is a prop, and the text between the tags is the children.

Is this HTML? No. The browser can't read it at all. Vite compiles it first, and this is what comes out:

import { jsx as _jsx } from "react/jsx-runtime";
const title = _jsx("h3", { className: "title", children: "Write report" });
const card = _jsx(TaskCard, { title: "Email Jack", owner: "Olivia", done: false });

So JSX is a function call: jsx(type, props), with the content passed in as children. The compiler even adds the import from react/jsx-runtime for you.

The element is a plain object

What does that jsx call return? The demo prints it:

title.type:  h3
title.props: { className: 'title', children: 'Write report' }
card.type:   [Function: TaskCard]
card.props:  { title: 'Email Jack', owner: 'Olivia', done: false }

title is an ordinary object with a type and props. We call it a React element. It is not on the page, and nothing has been drawn yet. It is only a description of an h3, and React reads it later to make the real one.

Look at card.type. For the TaskCard tag the type is not a string, it is the component function itself. That is why the capital letter matters: a capital letter means your own component, and lowercase means a plain HTML tag like h3.

A component: data in, JSX out

Here is the first component, TaskCard.tsx:

// A component: data (props) in, JSX out
type Props = {
  title: string
  owner: string
  done: boolean
}

export default function TaskCard(props: Props) {
  const label = props.done ? 'Done' : 'To do'
  const badge = props.done ? 'badge done' : 'badge'
  return (
    <div className="card">
      <h3>{props.title}</h3>
      <p>Owner: {props.owner}</p>
      <span className={badge}>{label}</span>
    </div>
  )
}

Lines 2 to 6 describe the props, the data the component takes in. Line 8 is the component, and it is just a function. It works out two small values from done, a label and a badge class, then returns a small tree of elements. Call it with done as false and then as true:

done: false  -> <span class="badge">To do</span>
done: true   -> <span class="badge done">Done</span>

Same function, new data, new page. And there is no step anywhere that changes the badge. You only describe it.

Components nest into a tree

To put cards on a page you write another component. App returns a heading and three cards, each with its own data:

import TaskCard from './TaskCard'

// The parent: a heading and three cards
export default function App() {
  return (
    <>
      <h1>Team tasks</h1>
      <TaskCard title="Write report" owner="Emma"
        done={true} />
      <TaskCard title="Email Jack" owner="Olivia"
        done={false} />
      <TaskCard title="Book flights" owner="Lucas"
        done={false} />
    </>
  )
}
App, TaskCard and plain tags as a tree App h1 TaskCard TaskCard TaskCard div.card h3 · p · span div.card h3 · p · span div.card h3 · p · span
App at the top, TaskCards under it, plain HTML tags at the bottom. The whole tree becomes the page.

Compiled, App is one jsxs call with a fragment and four children:

import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
return _jsxs(_Fragment, { children: [
_jsx("h1", { children: "Team tasks" }),
_jsx(TaskCard, { title: "Write report", owner: "Emma", done: true }),
_jsx(TaskCard, { title: "Email Jack", owner: "Olivia", done: false }),
_jsx(TaskCard, { title: "Book flights", owner: "Lucas", done: false })

The four JSX rules

JSX has a few rules. Each one makes sense once you remember that every tag is a function call.

Rule 1: one parent, or a fragment

// Wrong: two elements, and no parent around them
export function Header() {
  return (
    <h1>Team tasks</h1>
    <p>3 tasks</p>
  )
}

// Fixed: a fragment, <> ... </>, holds both
export function FixedHeader() {
  return (
    <>
      <h1>Team tasks</h1>
      <p>3 tasks</p>
    </>
  )
}

Header returns an h1 and a p side by side. That is two jsx calls, two values, and a function can return only one. Vite stops:

[PARSE_ERROR] Adjacent JSX elements must be wrapped in an enclosing tag.
Help: Did you want a JSX fragment `<>...</>`?

The fix is the fragment, the empty <> ... </>. It compiles to one call with both elements in its children, and it adds no element to the page. That is why the h1 and the three cards in App sit directly inside the root div with no extra wrapper.

Rule 2: className, not class

// Wrong: class, as we would write it in HTML
export function Badge() {
  return <span class="badge">To do</span>
}

// Fixed: className, the name JSX expects
export function FixedBadge() {
  return <span className="badge">To do</span>
}

JSX is JavaScript, and in JavaScript class already means something. TypeScript refuses it:

break-it/ClassName.tsx(3,16): error TS2322
  Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>'.
  Did you mean 'className'?

React also warns while rendering, and still writes the class:

Invalid DOM property `class`. Did you mean `className`?
class:     <span class="badge">To do</span>
className: <span class="badge">To do</span>

JSX attributes are props, named like the DOM properties. className sets the DOM property of the same name, which becomes class="badge" in the HTML.

Rule 3: curly braces run an expression

// What curly braces put on the page
import * as server from 'react-dom/server'

const html = server.renderToStaticMarkup

const owner = 'Olivia'
const tasks = 3
const done = false

console.log(html(<p>Owner: {owner}</p>))
console.log(html(<p>Owner: owner</p>))
console.log(html(<p>{tasks + 2} tasks</p>))
console.log(html(<p>{done ? 'Done' : 'To do'}</p>))
console.log(html(<p>{owner.toUpperCase()}</p>))

Each line prints the HTML it produces:

<p>Owner: Olivia</p>
<p>Owner: owner</p>
<p>5 tasks</p>
<p>To do</p>
<p>OLIVIA</p>

With braces, owner becomes Olivia. Without them you get the word "owner". Inside the braces any JavaScript expression works: a variable, a sum (3 + 2 gives 5), a ternary, a method call. Anything that gives back a value.

Rule 4: close every tag

// Wrong: an <input> that is never closed
export function DoneBox() {
  return (
    <label>
      <input type="checkbox">
      Done
    </label>
  )
}

// Fixed: a self-closing tag, <input />
export function FixedDoneBox() {
  return (
    <label>
      <input type="checkbox" />
      Done
    </label>
  )
}

The compiler keeps a list of open tags. It opens label, then input, then meets </label> while the input is still open:

break-it/Closing.tsx(5,8): error TS17008
  JSX element 'input' has no corresponding closing tag.

HTML lets an input stay open. JSX never does. Write <input /> and it closes itself.

Into the page with createRoot

index.html has one empty <div id="root"> and nothing else. main.tsx hands it to React:

import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App'

// the one empty <div id="root"> in index.html
const el = document.getElementById('root')!
// React takes over that element ...
const root = createRoot(el)
// ... and draws the whole App tree inside it
root.render(<App />)
index.html: <div id="root"></div> -> 0 children
after render: 4 children
  h1        Team tasks
  div.card  Write report | Owner: Emma | Done
  div.card  Email Jack | Owner: Olivia | To do
  div.card  Book flights | Owner: Lucas | To do

Before render the div has zero children. createRoot(el) tells React it owns that div from now on, and root.render(<App />) calls App, then each TaskCard, and puts four children inside: the h1 and three cards.

Common mistakes

  • Writing a lowercase component name like taskCard. React then treats it as an HTML tag, not your function.
  • Returning two sibling elements without a fragment.
  • Copying HTML into JSX and keeping class or an unclosed <input>.
  • Forgetting the braces, so the page shows the variable's name instead of its value.
  • Thinking a React element is on the page. It is only an object until React renders it.

Recap

IdeaIn one line
Why ReactDescribe the page as a function of the data; React works out the steps
JSXCompiles to jsx(type, props) calls that return plain objects
ComponentA capitalised function: props in, JSX out
TreeComponents nest; the tree becomes the page
RulesOne parent, className, braces for expressions, closed tags
createRootTakes the empty root div and renders the App tree into it

Try it yourself: add a fourth TaskCard to App with your own title and owner, then delete the fragment and read the error Vite gives you. Next, props and composition shows how components share data and layout.

Keep going in React · 15 of 59

Previous
TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
Next post
React Props and Composition: Data Down, Calls Up, Children in the Slot
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • Two ways to change a page
  • Building and changing a card by hand
  • What JSX really is
  • The element is a plain object
  • A component: data in, JSX out
  • Components nest into a tree
  • The four JSX rules
  • Rule 1: one parent, or a fragment
  • Rule 2: className, not class
  • Rule 3: curly braces run an expression
  • Rule 4: close every tag
  • Into the page with createRoot
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.