React7h estimated

Components & JSX

Difficulty
Importance

The problem

Building a UI directly with imperative DOM calls (createElement, appendChild) for anything nontrivial becomes unmanageable fast — components let you describe what a piece of UI should look like as a reusable function, instead of a manual sequence of DOM mutation steps.

Why now

Functions and scope already established the reusable, callable unit of logic; the DOM as a tree already established what's being built. A React component is those two ideas fused — a function that returns a description of DOM tree structure — and JSX is the syntax that makes writing that description look like the HTML it produces.

Mental model

A component is a function from data to a description of UI — call it, get back a tree description, not the real DOM yet. JSX is not HTML; it's syntax sugar that compiles to plain function calls (createElement(...)) building that description — which is why JSX expressions can embed real JavaScript freely, they're just function arguments.

Requires

Unlocks

Used in

Projects

  • Write the same small UI two ways — using JSX, and using raw React.createElement calls — and confirm they produce identical output
  • Build three small reusable components (a Button, a Card, an Avatar) and compose them into one larger UI

Examples

  • function Greeting({ name }) { return <h1>Hello, {name}</h1>; } is a function returning a UI description, nothing more magical than that
  • <h1>Hello, {name}</h1> compiles to React.createElement('h1', null, 'Hello, ', name) — plain function calls underneath

Resources

Mastery checklist