Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 2

From Mockup to Component Tree

Break a design into a hierarchy of components, write your first JSX, and compose larger interface pieces from smaller ones through props and children.

Contentsand lesson path

On this page

  1. Why it matters
  2. Reading the mockup
  3. JSX and composition
  4. Props are read-only
  5. Check your understanding
  6. Apply it
  7. Review prompt

Lessons of React Components & State

  1. From Mockup to Component Tree Concept · 20 min
  2. JSX, Typed Props and Composition Worked example · 25 min
  3. State, Events and Immutable Updates Worked example · 25 min
  4. Lists, Keys and When React Re-renders Concept · 20 min
  5. Lab: A Filterable, Sortable Product Table Lab · 30 min
  6. Check: Predict the Component Behavior Knowledge check · 6 questions

What you will learn

  • Break a UI design into a component hierarchy and implement it with JSX, typed props and composition through children.

Prerequisites: JavaScript Foundations

01. Why it matters

In plain JavaScript, a page is a document you reach into and patch: query an element, change its text, add a class. In React, a page is a tree of components — functions that take data in and return a description of user interface. The browser never sees your components; React calls them and updates the document so it matches what they returned. Once that model clicks, building an interface stops being a sequence of manual edits and becomes writing functions that describe what the screen should look like for the data at hand.

Getting the tree right is the first skill, and it is a design skill more than a coding one. A good split gives you three things:

  • Reuse: a card written once renders ten different records.
  • Isolation: when a date renders wrong, you know which function owns the bug.
  • Readable files: each component is small enough to hold in your head.

A bad split costs the same three things in reverse: one giant component nobody dares to touch, or a wrapper around every tag that adds nesting without adding meaning. This lesson gives you a repeatable way to read a mockup and turn it into that tree, then shows the JSX and composition rules the tree is written in.

02. Reading the mockup

Start from the design, not from the code. Draw boxes around every part of the mockup, then ask two questions about each box. First, does it have one job — something you could describe in a sentence without saying "and then"? Second, does the same structure appear more than once, with different data? A box that passes either question is a candidate component; a box whose name is a place ("the left column") rather than a thing ("a price row") usually is not.

The way the boxes sit inside each other in the design almost always becomes the way the components nest in code. Here is a small mockup for a team page, drawn as text:

From mockup boxes to a component tree
Mockup:                     Component tree:

+---------------------+     ProfileCard
| TEAM MEMBER         |     └── Card  (title: "Team member")
| (AO)                |         ├── Avatar  (initials: "AO")
| Ada Okafor,         |         └── text: "Ada Okafor,
| platform engineer   |                 platform engineer"
+---------------------+

Reading it from the outside in: the whole thing is one ProfileCard. The framed box with the heading is a Card that will frame other things on other pages too, so it takes its heading as data. Inside, the initials badge is an Avatar, and the remaining text is content the page passes in. Notice what did not become a component: the heading inside the card is part of Card's one job, and the text line has no structure of its own. Wrapping those would add indirection, not meaning.

The HTML elements you eventually choose inside each component are a separate decision, guided by meaning rather than by the drawing — choosing elements by meaning covers that. A component is a unit of interface purpose; an element is a unit of document meaning.

03. JSX and composition

Components are functions that return JSX — a syntax that looks like HTML but is really a compact way to write function calls. Element names starting with a capital letter are your own components; lowercase names are the built-in elements such as section or h2. Braces {…} embed any JavaScript expression in the output. Two small differences from HTML trip everyone once: the class attribute is written className, and every tag must be closed, with </h2> or with /> for empty elements.

Here is the mockup above as a component file. Card demonstrates the most important composition tool in React: whatever a caller places between its opening and closing tags arrives as the children prop:

JSX · profile-card.tsx
import { renderToString } from 'react-dom/server';
import type { ReactNode } from 'react';

function Avatar({ initials }: { initials: string }) {
  return (
    <span className="avatar" aria-hidden="true">
      {initials}
    </span>
  );
}

function Card({ title, children }: { title: string; children: ReactNode }) {
  return (
    <section className="card">
      <h2>{title}</h2>
      {children}
    </section>
  );
}

function ProfileCard() {
  return (
    <Card title="Team member">
      <Avatar initials="AO" />
      <p>Ada Okafor, platform engineer</p>
    </Card>
  );
}

console.log(renderToString(<ProfileCard />).replaceAll('><', '>\n<'));
Expected output · node --import tsx src/profile-card.tsx
<section class="card">
<h2>Team member</h2>
<span class="avatar" aria-hidden="true">AO</span>
<p>Ada Okafor, platform engineer</p>
</section>

Read the output next to the code and the model becomes concrete: React turned the JSX of three nested components into plain HTML elements, in the same nesting order as the mockup. (React writes that HTML as one long line; the demo splits it at tag boundaries with replaceAll purely so it fits on this page — nothing about the rendering changes.) The example prints its result with renderToString, which runs the tree once and returns the HTML as text — a handy way to see what React renders without opening a browser. To run it yourself, install react, react-dom and tsx, and give the project a tsconfig.json that sets "jsx": "react-jsx"; without that setting the run stops with ReferenceError: React is not defined, for a reason the next lesson explains. Real applications render into the document instead; the browser rendering skill describes how that rendering reaches pixels.

Composition is what made this work. ProfileCard did not copy the markup of a card; it asked Card to frame some content by passing that content as children. Configuring with props (title, initials) sets values; composing with children hands over whole pieces of interface. Prefer children when the wrapper should not know or care what it wraps — that is what keeps Card reusable on the next page.

04. Props are read-only

Props are the inputs of a component, and one rule governs them: a component never changes its own props. It receives them, reads them, and returns output. The same mockup data must render the same interface — props flowing down and output flowing up is what makes a component predictable and safe to reuse. The worked example that follows builds on this with TypeScript types, and the next lesson adds the one thing a component is allowed to own and change: its state.

One more habit to start now: name components after what they show, not where they sit. PriceRow can outlive a redesign; LeftBox cannot.

05. Check your understanding

Practice check · 3 questions

From mockup to components

Three situations from real design work.

Q1. You open a design file for a settings page. Which observation is the strongest signal that a part of it should become its own component?
Q2. A page renders `Page` with `Sidebar` and `Article` written between its opening and closing tags. How does `Page` receive them?
Q3. A component holds the running total in a variable named `total`. Which line of JSX displays the number?
Practice only: not graded, not saved, not evidence.

06. Apply it

Take the shopping-list design from the practice brief for this skill and repeat this lesson's pass on paper: draw the boxes, name each candidate component with a noun, and mark which ones repeat. Write down for every box its one sentence of responsibility and the data it needs. Keep the sketch — the worked examples over the next three lessons build exactly this screen, and the lab finishes it. If you want the fuller method, read Thinking in React, which walks the same path from screenshot to tree.

07. Review prompt

Without looking back: sketch any interface you built recently and redraw it as a component tree, naming each component and its one job. Then answer in one sentence each — why is className written that way, what arrives in the children prop, and why must a component not edit its own props?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check