Skip to content
build-3000
frontend

Components and User Interfaces

Building screens from reusable pieces - the Lego bricks of every modern app.

Before this: Anatomy of a Web App

Objective

Think in components - reusable UI pieces with inputs (props) and internal memory (state) - and direct an agent to compose interfaces instead of hand-crafting one-off screens.

Vocabulary

The words to use when directing your agent.

component
A self-contained, reusable piece of interface - a button, a card, a navbar.
prop
Data passed INTO a component to configure it, like arguments to a function.
state
Data a component remembers internally that can change over time.
render
The act of turning component data into what you see on screen.
framework
A toolkit (React, Vue, etc.) that standardizes how components are written and updated.

Understand it

Spotting components everywhere

Open any app: the video card, the sidebar item, the avatar bubble - each is likely ONE component fed DIFFERENT props. Training your eye to see the repeated unit is the core frontend skill.

Props down, events up

Data flows into components via props; components report user actions upward via events/callbacks. When your diagram of who-knows-what gets tangled, that is the smell prompting you to restructure state.

Core concepts

UI is a function of data

Modern frameworks redraw the screen automatically when state changes. You describe what the screen should look like for any given data; the machinery handles updating the pixels. Stop thinking in steps - think in states.

Composition beats duplication

One ExpenseCard component rendered forty times beats forty copy-pasted blocks. Change the component once, all forty update. Duplication is where UI bugs breed.

Examples

One card, many products

A shop page is one ProductCard component receiving name, price and image as props, rendered in a list. The 'page' is barely code at all - it is data mapped through one good component.

State you can point at

A counter has one piece of state (the count) and two events (+/-). Being able to enumerate an app's states like this is how you review an agent's UI work.

Common mistakes

Common mistake

Accepting copy-pasted near-identical UI blocks from the agent.

Fix

Rule for your agent: 'If markup repeats twice with different data, extract a component taking props.'

Common mistake

Storing the same fact in five places.

Fix

One owner per piece of state; everyone else receives props. Ask the agent to name the single owner of each fact.

Working with your AI agent

Before letting the agent build UI, make it list the components it plans, the props each takes, and which component owns each piece of state. Approve the PLAN, then let it code. Reviewing a component list takes a minute; reviewing tangled UI takes an hour.

Build it

The module’s real project. Your agent builds; you direct and inspect.

Project: Card Gallery

Direct your agent to build a gallery of cards from a data array - then prove composition works by changing the DATA ONLY and watching the UI update correctly.

Requirements

  • One Card component rendering title, description and a tag
  • Gallery renders at least six cards driven purely from a single data array
  • Editing one array entry (no other file touched) updates exactly that card
  • Empty array produces a friendly empty-state message, not a blank screen

Context for your agent

Build a small gallery app: a single Card component (title, description, tag) rendered repeatedly from one data array of at least six entries, plus a graceful empty state. First show me the planned component tree and state ownership for approval; implement only after I approve. No styling frameworks - clean minimal CSS is fine.

Verify it - twice

Check every item yourself first. Then hand your agent the prompt and compare verdicts.

Self-verified0/7
Functional
Architecture
Testing

Verification prompt - paste into your AI agent

Review my Card Gallery. Inspect the code and verify PASS or FAIL with file-level evidence: (1) a single Card component exists and no card markup is duplicated, (2) cards render exclusively from one data array - no hardcoded cards in markup, (3) an empty array yields the designed empty state, (4) README documents the component list and which piece owns each state. Then try renaming a field in the data array yourself and tell me every place that breaks - that reveals hidden couplings.

Run this against “Components and User Interfaces” after your own checklist pass. Where the agent and you disagree, investigate before moving on.

Review questions

Answer out loud. If you cannot, revisit before moving on.

  1. Pick any app on your phone: name three components inside it.

  2. What is the difference between a prop and state, in one sentence each?

  3. Why did we demand a component plan BEFORE letting the agent write UI?

You can now

  • See interfaces as compositions of reusable components
  • Demand component plans before approving agent UI work
  • Test UI changes by editing data, not markup

Up next

Forms and Input Validation