Skip to content

Module 05 · Lesson 5.2

Building Components with an Assistant

40 minUpdated 19 Nov 2026Part of Frontend and API Integration · New Project Creation
On this page
  1. What you will learn
  2. What a component is and why to build small ones
  3. Small steps and limits: how to prompt for one component
  4. Worked scenario: SlotList and BookingCard for Tidewell
  5. Reviewing generated components: a checklist
  6. Step-by-step workflow
  7. What the assistant can and cannot do when building components
  8. Conclusion and your next step
  9. Reusable prompt
  10. Expected output
  11. Common errors and fixes
  12. Validation checklist
  13. Hands-on exercise
  14. Knowledge check
  15. Frequently asked questions
  16. References

A child can build a castle from small bricks and, with help, can see which brick is crooked. Hand them a whole castle in one piece and nobody can tell what is wrong with it. Generated interface code works the same way. A whole page from one prompt is hard to review. A single component is easy.

In this lesson you build the first pieces of Tidewell's booking screens with an AI assistant. You ask for one component at a time, set limits in the prompt, and review the result with a checklist. You also render each component to HTML so you can see exactly what it produces, without opening a browser.

What you will learn

  • Explain what a component, a prop and a client component are, in plain words.
  • Write a prompt that gives an assistant one small component to build, with clear limits.
  • Review generated component code with a checklist before keeping it.
  • Test a component by rendering it to HTML and reading the result.

Before you start

  • Completed Planning Screens from Workflows, or have a screen plan of your own.
  • Access to any capable AI assistant.
  • Optional: Node.js and the project from earlier lessons, if you want to run the examples.

What a component is and why to build small ones

A component is a reusable piece of an interface. A list of free times is one. A card that shows a booking is another. You build a screen by putting components together, the way you build a wall from bricks.

Small components are easier to read, easier to test and easier to reuse. They are also easier to review, which matters most when an assistant wrote them. You can read twenty lines closely. You cannot read four hundred lines the same way.

Component
A function that returns a piece of interface. Like one brick, with a fixed shape you can use many times.
Props
The settings you hand to a component, such as the list of slots to show. Like the label on a tin: the tin is the same, the label changes.
Presentational component
A component that only shows what it is given. It does not fetch data or remember anything. Like a picture frame: it displays, it does not choose the picture.
Client component
In Next.js, a component that runs in the browser so it can remember things and react to clicks. You mark it with "use client" on the first line. Like a shop assistant who answers questions, as opposed to a poster.
Render
To turn a component and its props into HTML. Like pressing a stamp: the shape is the component, the ink is the data.

Most of Tidewell's components are presentational. A few client components hold state and call the API. Keeping the two apart makes the presentational ones trivial to test.

Small steps and limits: how to prompt for one component

The order matters. Build from the bottom up: types first, then presentational pieces, then the client component that ties them to the API. Each step is its own prompt, its own review and its own commit.

  1. Types that match the API contract, so every later piece knows the shape of the data.
  2. Presentational components, such as SlotList and BookingCard.
  3. Small shared messages, such as StatusMessage and ProblemMessage (next lessons).
  4. The client component that loads data and holds state.

Limits to put in every component prompt

An assistant fills any gap with a guess. Limits close the gaps. They are the difference between 'a list of slots' and 'the list of slots that fits this project'.

  • Scope: build only this component. Do not change other files or add features.
  • Inputs and outputs: give the exact props with their types, copied from your contract.
  • Stack: TypeScript with strict checks, React in a Next.js App Router project, no new libraries.
  • Behaviour: no data fetching and no state in a presentational component.
  • Accessibility: native elements, a list for lists, a real button for actions.
  • Output: the component file only, and a short note listing anything it assumed.

Worked scenario: SlotList and BookingCard for Tidewell

Screen S1 shows free times. The API sends each slot with a start and end time in UTC, which is the world's reference time. Patients expect clinic time. So the first helper converts UTC to the clinic's time zone, and it is the only place in the code that does so.

TypeScriptsrc/lib/format.ts
// The clinic is in the United Kingdom, so patients see clinic time.
// The API sends UTC; this is the only place that converts it.
export const CLINIC_TIME_ZONE = "Europe/London";

export function formatTime(iso: string): string {
  return new Intl.DateTimeFormat("en-GB", {
    timeZone: CLINIC_TIME_ZONE,
    hour: "2-digit",
    minute: "2-digit",
    hour12: false,
  }).format(new Date(iso));
}

export function formatDay(iso: string): string {
  return new Intl.DateTimeFormat("en-GB", {
    timeZone: CLINIC_TIME_ZONE,
    weekday: "long",
    day: "numeric",
    month: "long",
    year: "numeric",
  }).format(new Date(iso));
}

The clinic is assumed to be in the United Kingdom for this example. Change the zone if yours is elsewhere.

What each part does

  • CLINIC_TIME_ZONE names the zone once, so a change is one edit.
  • formatTime turns "2026-12-01T09:00:00Z" into a short time such as "09:00". It uses Intl.DateTimeFormat, which is built into the browser and Node.
  • formatDay returns a long date for the booking card. Both functions take the time as text, exactly as the API sends it.

Now the first component. It takes a list of slots and shows each as a list item. It does not fetch anything.

TypeScript (TSX)src/components/SlotList.tsx
import type { FreeSlot } from "../features/bookings/types";
import { formatTime } from "../lib/format";

export function SlotList({ slots }: { slots: FreeSlot[] }) {
  return (
    <ul className="slot-list">
      {slots.map((slot) => (
        <li key={slot.slotId}>
          <time dateTime={slot.startsAt}>{formatTime(slot.startsAt)}</time> to {formatTime(slot.endsAt)}
        </li>
      ))}
    </ul>
  );
}

What each part does

  • { slots }: { slots: FreeSlot[] } says the only input is a list of free slots, typed from the contract.
  • <ul> and <li> are the native list elements. A screen reader announces how many items the list has.
  • key={slot.slotId} gives each item a stable identity so React can update the list correctly.
  • <time dateTime=...> marks the start as a machine-readable time. People see "09:00"; software can read the full value.

To test it without a browser, render it to HTML with renderToStaticMarkup from react-dom/server. This function turns a component into a plain HTML string. The helper below also puts each tag on its own line so the result is easy to read.

TypeScript (TSX)tests/test-components.tsx
// Test helper only: put each tag on its own line so the output is easy to read.
function show(name: string, element: ReactElement) {
  console.log("== " + name + " ==");
  console.log(renderToStaticMarkup(element).replace(/></g, ">\n<"));
}

const slots: FreeSlot[] = [
  { slotId: 12, startsAt: "2026-12-01T09:00:00Z", endsAt: "2026-12-01T09:45:00Z" },
  { slotId: 13, startsAt: "2026-12-01T10:00:00Z", endsAt: "2026-12-01T10:45:00Z" },
  { slotId: 14, startsAt: "2026-12-01T11:00:00Z", endsAt: "2026-12-01T11:45:00Z" },
];

Part of the test script: a small helper and the sample data.

TypeScript (TSX)tests/test-components.tsx
show("SlotList", <SlotList slots={slots} />);
show("BookingCard", <BookingCard booking={booking} />);

The calls that render the two components.

Real output: SlotListCaptured from a real run
<ul class="slot-list">
<li>
<time dateTime="2026-12-01T09:00:00Z">09:00</time> to 09:45</li>
<li>
<time dateTime="2026-12-01T10:00:00Z">10:00</time> to 10:45</li>
<li>
<time dateTime="2026-12-01T11:00:00Z">11:00</time> to 11:45</li>
</ul>

Read the output the way a reviewer would. There is one list with three items. Each time is inside a time element. The times are 09:00, 10:00 and 11:00, which matches the UTC values because the date falls in winter, when UK time equals UTC. The attribute shows as dateTime because React spells it that way. HTML ignores the difference in letter case.

Next comes the card for one booking. It takes a booking and, optionally, buttons or links to show inside it.

TypeScript (TSX)src/components/BookingCard.tsx
import type { ReactNode } from "react";
import type { Booking } from "../features/bookings/types";
import { formatDay, formatTime } from "../lib/format";

export function BookingCard({ booking, children }: { booking: Booking; children?: ReactNode }) {
  const headingId = "booking-" + booking.bookingId;
  return (
    <article className="booking-card" aria-labelledby={headingId}>
      <h3 id={headingId}>{booking.clinicianName}</h3>
      <p>
        <time dateTime={booking.startsAt}>{formatDay(booking.startsAt)}</time>, {formatTime(booking.startsAt)} to{" "}
        {formatTime(booking.endsAt)}
      </p>
      <p>Status: {booking.status === "booked" ? "Booked" : "Cancelled"}</p>
      {children}
    </article>
  );
}
Real output: BookingCardCaptured from a real run
<article class="booking-card" aria-labelledby="booking-7">
<h3 id="booking-7">Physiotherapist A</h3>
<p>
<time dateTime="2026-12-01T09:00:00Z">Tuesday, 1 December 2026</time>, 09:00 to 09:45</p>
<p>Status: Booked</p>
</article>

The card is an article named by its own heading through aria-labelledby. The children slot lets S3 add a Move or Cancel button without the card knowing about either. That is what keeps it small.

Reviewing generated components: a checklist

Generated components usually look fine. The problems are in what they quietly add. Review each one against the list below before you keep it. This is a short version of the AI-Generated Code Review Checklist.

CheckWhat to look forWhy it matters
ScopeOnly the component you asked for. No extra files, no changed config.Extra files are unreviewed code.
TypesProps use the contract's types. No any.any switches off the checks that catch wrong field names.
DependenciesNo new package in package.json.Every package is code you must trust and update.
BehaviourA presentational component does not fetch, store or log.Hidden fetching makes components hard to test.
ElementsLists are lists, actions are buttons, links are links.Native elements give keyboard and screen-reader support for free.
Text and dataNo invented clinic names, prices or rules in the text.Made-up content looks real to patients.
SecretsNo keys, tokens or addresses typed into the code.Frontend code is visible to everyone who opens the page.

Then run it. Type-check it with npm run typecheck. Render it with the test helper and read the HTML. If the output surprises you, the code is not what you thought it was.

Step-by-step workflow

  1. Step 1: Pick one component from the screen plan

    Choose the smallest piece that you can describe in one sentence, such as 'a list of free slots'.

    What you should see: One component name and its props written down.

  2. Step 2: Write the prompt with limits

    Use the prompt card. Paste the types and the screen's plan entry. State what the component must not do.

    What you should see: A prompt that names the inputs, the stack and the limits.

  3. Step 3: Read the code before running it

    Go through the review checklist. Remove or question anything you did not ask for.

    What you should see: A list of changes to ask for, or 'accepted'.

  4. Step 4: Type-check and render it

    Run the type check. Render the component with sample data and read the HTML.

    What you should see: A clean type check and HTML that matches what you expected.

  5. Step 5: Commit and move to the next piece

    Commit the single component with a clear message. Only then ask for the next one.

    What you should see: One small commit per component.

One component at a time
  1. Pick

    One component

  2. Prompt

    Props and limits

  3. Review

    Checklist

  4. Render

    Read the HTML

  5. Commit

    One small change

The loop is short on purpose. A crooked brick is easy to spot when it is the only new one.

What the assistant can and cannot do when building components

An assistant writes component code quickly and usually correctly for simple cases. It does not know your project's rules unless you give them, and it cannot see the screen. Treat its output as a first draft from a keen junior colleague.

TaskAssistant's partYour part
Writing the first draftProduce the component from your types and limits.Supply the types and the limits, and read every line.
Choosing elementsSuggest native elements.Check that each one fits the job, for example a button for an action.
Adding testsDraft a render test with sample data.Check that the test reads the output and would fail if the component broke.
Wording textSuggest plain wording.Check names, times and rules against the client's decisions.
Choosing a libraryNothing. Mention options only if asked.Decide whether a new package is worth its upkeep.

Conclusion and your next step

Small components are easy to ask for, easy to read and easy to test. You give the assistant the types, the plan entry and clear limits, and you review the result with a checklist. Rendering to HTML lets you see what the component really produces.

Your next step: build one component from your own screen plan with an assistant and review it with the table above. Then continue to Calling the API from the Frontend, where you connect these pieces to real data.

For more help, the Screen to Component Plan prompt breaks a screen into components, and AI-Generated Code Review Checklist is a longer review list. The article AI Code Review: Catching Bugs Before They Ship goes deeper on reviewing generated code.

Reusable prompt

Single component builder

Asks for one presentational component with exact props, a limited scope and a note of assumptions.

You are helping me build one interface component. Build only this component. Do not change other files, add libraries or add features.

Project: Tidewell Physiotherapy booking system (fictional). Next.js App Router, React, TypeScript with strict checks. Never put keys or secrets in the code.

Component: SlotList in src/components/SlotList.tsx. It is presentational: it must not fetch data, hold state or log anything.
Props: { slots: FreeSlot[] }
Types (already exist in src/features/bookings/types.ts):
interface FreeSlot { slotId: number; startsAt: string; endsAt: string }
startsAt and endsAt are ISO 8601 strings in UTC. Show them in clinic time with the existing formatTime function from src/lib/format.ts.

Screen plan entry: S1 Choose a clinician and date, then see free slots (FR-01). The screen has loading, empty, error, ready, submitting and conflict states. This component only draws the ready state.

Rules:
1. Use native elements: a list with one item per slot.
2. Give each item a stable key from slotId.
3. Mark the start time with a time element.
4. No inline styles. Use a className only.

Output: the component file only, then a short list of anything you assumed.
Show the reusable template

Replace each {{placeholder}} with your own details.

You are helping me build one interface component. Build only this component. Do not change other files, add libraries or add features.

Project: {{project_and_stack}}. Never put keys or secrets in the code.

Component: {{component_name}} in {{file_path}}. It is {{presentational_or_client}}: {{what_it_must_not_do}}.
Props: {{props}}
Types (already exist in {{types_file}}):
{{types}}

Screen plan entry: {{screen_plan_entry}}. This component only draws: {{states_it_draws}}.

Rules:
{{rules}}

Output: the component file only, then a short list of anything you assumed.

Expected output and limitations

One component file that matches your props, uses native elements and does not fetch data, followed by a short list of assumptions. Nothing else should have changed.

Sample responseIllustrative — your output will differ
// src/components/SlotList.tsx
import type { FreeSlot } from "../features/bookings/types";
import { formatTime } from "../lib/format";

export function SlotList({ slots }: { slots: FreeSlot[] }) {
  return (
    <ul className="slot-list">
      {slots.map((slot) => (
        <li key={slot.slotId}>
          <time dateTime={slot.startsAt}>{formatTime(slot.startsAt)}</time> to {formatTime(slot.endsAt)}
        </li>
      ))}
    </ul>
  );
}

Assumptions:
- formatTime accepts an ISO string and returns a short clinic-time string.
- An empty list is handled by the parent, not by this component.

Limitations to keep in mind

  • The assistant may add things you did not ask for, such as a loading message, extra props or a styling library. Remove them or ask again with a tighter limit.
  • It cannot see how the component looks. Colour, spacing and phone-width problems still need your own check.
  • A sample that type-checks is not proof that it is right. Render it and read the HTML.

Common errors and how to fix them

The assistant builds a whole page, including data fetching, in one answer.

Why it happens: The prompt named a screen and not a single component.

Fix: Ask for one presentational component at a time, with its exact props.

The component uses any or invents field names.

Why it happens: The real types were not in the prompt.

Fix: Paste the types from your contract and say 'no any'.

A clickable div stands in for a button.

Why it happens: The prompt did not ask for native elements.

Fix: Add 'use native elements: button for actions, a for links' to your limits and review for it.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

A Ferngate low-stock badge

Ferngate Cycle Repairs wants to show a small badge beside each part on the stock screen. Write a prompt for one presentational component, run it with an assistant, review the result with the checklist and render it for three inputs.

You will need

  • Props: { partName: string; quantity: number; lowStockAt: number | null }.
  • Note: the low-stock threshold is still 'to be agreed', so lowStockAt can be null.
  • Note: mechanics use a shared tablet with greasy hands, so the text must be large and clear.

Acceptance criteria

Your work is done when every one of these is true.

Hints (2)
  • A badge that is only red is invisible to some people. Add words.
  • Decide what 'quantity below the threshold' means when the threshold is null. Ask the owner rather than choosing.
Show a model answer

A strong answer gives the assistant the exact props and says the component must not fetch or decide the threshold. It handles null by showing the plain quantity with no 'low' label, and notes that the threshold is a decision for the owner. The three renders are: plenty in stock, below the threshold and no threshold set. The review notes might record that the assistant added a colour library or used a red background with no text, and that you removed the first and added the word 'Low' to the second. Check that your HTML uses a text label and does not depend on colour alone.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.Why ask an assistant for one component at a time?
    Show the answer and explanation

    Answer: B. Small pieces are easy to review and to undo. Assistants can write big pages, which is why 'they cannot' is wrong, but large output hides mistakes. Token use may be lower, but that is a side effect, not the reason.

  2. 2.What does renderToStaticMarkup give you in a test?
    Show the answer and explanation

    Answer: B. It returns HTML as text, which you can read or compare. It is not a screenshot, so it cannot show colour or spacing. It also does not check accessibility, although you can see in the HTML whether labels and roles are present.

  3. 3.The assistant adds a styling library while building SlotList. What do you do?
    Show the answer and explanation

    Answer: B. A new library is code you must trust and update, and nobody approved it. 'Already written' is tempting but is not a reason. Keeping it unused still leaves it in the project.

Frequently asked questions

What is a React component?

It is a function that returns a piece of interface, such as a list or a card. You give it settings called props, and it returns what to show. You combine small components to build a screen.

What does "use client" mean in Next.js?

It marks a file as a client component, which runs in the browser so it can hold state and react to clicks. Components without it are server components by default in the App Router. Keep the marked ones small, and keep presentational pieces free of it where you can.

How do I test a React component without a browser?

Render it to HTML with renderToStaticMarkup from react-dom/server and check the text. This is quick and works in plain Node. For clicks and typing you need a browser-like test tool, which comes in Module 7.

How do I stop an AI assistant adding features I did not ask for?

Say what it must not do, in the prompt: no other files, no new libraries, no extra props. Ask it to list its assumptions. Then review the result against your checklist and reject anything outside the request.

Written by
PromptFable Editorial
Last updated 19 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.