A React Native Component Library for AI-Generated Code
How a small library keeps generated screens consistent.
Hello. In this lesson I will take you through 3 ideas, one at a time.
Why it matters: How a small library keeps generated screens consistent. After each idea I will ask you one quick question.
In this lessonFollows you as you read
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.
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.
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.
- 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
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.
Mark it complete to track your progress on this device.