Lesson 2 of 4 · 30 min

A React Native Component Library for AI-Generated Code

How a small library keeps generated screens consistent.

XDQ Tutor · AI guide

Hello. In this lesson I will take you through 3 ideas, one at a time.

  1. Why the library comes first
  2. Tokens, not values
  3. Documenting for agents

Why it matters: How a small library keeps generated screens consistent. After each idea I will ask you one quick question.

Why the library comes first

The short version: If an agent can write raw views and inline styles, it will.

If an agent can write raw views and inline styles, it will. Each screen then carries its own version of a button. Build the library before the screens: buttons, inputs, cards, lists, headers, empty states and a screen wrapper that handles safe areas and loading.

Then tell the agent it may only use these components and the theme tokens. The rule is simple to check in review and simple to enforce with a lint rule that bans inline colours.

Quick check

What should screens be allowed to use?

Tokens, not values

The short version: Put colours, spacing, radius and type sizes in one theme file.

Put colours, spacing, radius and type sizes in one theme file. Components read tokens, screens read components. When the client changes the brand colour, one file changes.

This also makes apps for several businesses from one codebase possible. The theme becomes data, loaded per business, and the screens do not change at all.

Quick check

What do you do when the library lacks a needed component?

Documenting for agents

The short version: Agents use what they can see.

Agents use what they can see. Keep a short reference file listing each component, its props and one example. Include what not to do. A reference of two pages is read every time. A reference of twenty is skimmed.

When an agent builds something the library lacks, do not accept a one-off. Add the component to the library first, then let the screen use it.

Key takeaways
  • Build the library before the screens
  • Ban inline styles with a lint rule
  • Themes are data, so one codebase can serve many brands
  • A short reference beats a long one
Try it

List the ten components your next app needs. For three of them, write the props and one usage example as you would for an agent.

That is the lesson.
Mark it complete to track your progress on this device.
← PreviousHow to Write React Native Screen Specs for AI AgentsNext lesson →Typed API Clients: Stopping AI-Invented Endpoints