Five Reusable Skills to Tame AI When Writing React
Why ad-hoc prompting fails when you use AI to write React, and how five version-controlled skill files—covering planning, a project state index, type safety, design tokens, and directory and routing rules—turn team conventions into engineering guardrails that make AI output reviewable and mergeable.
Why Verbal Instructions Fail to Tame AI Writing React
The first ten minutes of collaborating with AI on React are often impressive; half a day later, your blood pressure starts rising. The reason is not mysterious: a large language model’s default preference is the “general best solution,” while an engineering team needs the “only solution for this project.” The gap usually concentrates on a few recurring points—components missing prop types, instructions that only apply to a specific rendering environment added offhandedly, magic numbers hard-coded in styles, and page components placed in directories that conflict with existing conventions.
The traditional approach is to paste project standards into the prompt over and over. That has three problems. First, the context window is limited, and long standards dilute the constraints that actually matter. Second, standards are “soft constraints”: the model may follow them or ignore them. Third, standards drift—once a component is refactored, the paths in the prompt are immediately outdated. What is needed is a mechanism that turns conventions from “suggestions in a conversation” into “rails in the codebase.”
The core idea below is to capture team conventions as skill description files (sets of Markdown instructions) in the project root, which AI coding tools automatically match and load based on task semantics. This is not a longer prompt; it is a versionable, reviewable, reusable engineering asset.
Skill 1: Plan First, Move Rework Ahead of Coding
AI’s most typical flaw is impatience: one sentence like “add a filter” and it immediately spreads across a dozen files, guessing at every edge case. The trigger condition for a planning skill should be written forcefully—for example, when describing a new feature, a new page, or a larger change, it must enter planning mode first, and no business code is written until a confirmed plan exists.
Effective planning is not listing directories; it is aligning on decision points one by one:
- Data source and request timing: whether the request fires on first render, whether it is cached, whether failures are retried;
- Interaction details: whether input is debounced, the basis for the debounce interval, how repeated clicks are made idempotent;
- State completeness: loading, empty data, partial failure, no permission, extremely long text, extreme time zones and localization;
- Reuse strategy: whether a similar component already exists to extend; copy-and-paste creation is forbidden;
- Acceptance criteria: what counts as done, and which self-test cases are required.
The key constraint is “read before write”: the planning phase must first search existing implementations and convention documents, then output the plan; implementation begins only after a human confirms the plan. This moves a large number of design flaws that should surface during review to before code generation, turning review from “fault-finding” into “confirmation.”
Skill 2: Maintain a Project State Index So AI Does Not Use an Outdated Map
Standards change, and directories move. A component that was somewhere yesterday has moved today, yet AI still drops files at the old path—essentially because it lacks awareness of the repository’s current shape. The solution is to maintain a minimal project state index, such as a state file in the repository root, that records only “facts” and no commentary.
The index should keep only a structure that machines can scan quickly:
## Directory conventions- Page-level components: src/features/<domain>/pages- Shared components: src/components/ui- Request layer: src/features/<domain>/api## Change log- 2024-xx-xx User center components moved to features/account- 2024-xx-xx Design tokens are now all exported from the tokens file
The accompanying skill rule should be explicit: after any file or route is added, deleted, renamed, or moved, or after dependencies or the token source change, the corresponding line must be updated immediately; descriptions unrelated to facts are forbidden. Other skills read the index first at startup, then decide where to place code. The benefits of this file extend beyond AI: when a new teammate joins or teams collaborate across projects, it is also a low-cost description of the current state.
Skill 3: Type Safety, No Assertions to Hide Design Problems
Loss of control at the type level is often not about “not knowing how” but about “taking the easy way.” A skill should write red lines as decidable conditions rather than vague appeals:
- No implicit or explicit any; when something genuinely cannot be modeled, use unknown and narrow it at the boundary;
- No forcing checks to pass with type assertions; fix the data structure and interface contract first;
- External data (API responses, global objects injected by scripts) must be validated at runtime before use;
- Nullable fields must be expressed truthfully in types; non-null assertions to silence warnings are forbidden;
- Exported functions and components need explicit parameter and return types, avoiding broadly inferred types.
Equally important are the supporting engineering measures: turn on strict mode and stricter checks so violations fail at save and commit time. Skills handle “intent,” static checks handle the “safety net,” and only the two together are stable.
Skill 4: Styles and Design Tokens, No Magic Values
The root of style chaos is the lack of a single source of truth. The skill should require that colors, spacing, radii, shadows, and font sizes all come from design tokens or theme variables; hard-coding specific color values or pixels inside components is forbidden; breakpoints and container widths use a shared wrapper; one visual semantic allows only one token name.
Illustrative usage:
// Recommended: semantic tokens<div className="rounded-lg bg-surface p-4 text-content-primary" />// Forbidden: magic values<div style={{ background: "#3b82f6", padding: 13 }} />
Also agree on responsive and accessibility baselines: interactive elements need a visible focus state, color contrast must meet requirements, and icon buttons must have readable labels. Writing these into the skill avoids the fragmentation of “a different aesthetic on every page.”
Skill 5: Directory and Routing Constraints for Predictable Structure
Structural drift carries the highest cost, because it keeps polluting every subsequent change. The skill needs to lock down placement rules: page components go in their business domain directory, cross-domain shared components are pushed down to the shared layer, requests and type definitions live close to the business domain; every new route must be registered in the state index at the same time; assembling request details directly inside page components is forbidden.
Pair this with a “minimal change” principle: do not opportunistically refactor unrelated files, do not do purely stylistic bulk replacements, and avoid review noise drowning out the real changes. Once structure is predictable, AI output can be reviewed and reused reliably.
Implementation Advice: Making the Skills Actually Work
- Write specific trigger conditions. Replace “consider referring to” with “must load when this kind of task appears,” reducing the model’s room for discretion.
- Keep it lean. One skill solves one class of problem; excessive length dilutes them against each other—split in layers rather than piling up.
- Put it under version control. Skill files are reviewed in the same repository as the code, so standard changes leave a traceable history.
- Double insurance. Skills manage intent; static checks, commit hooks, and continuous integration manage the baseline, and no layer should be skipped.
- Review periodically. If a certain kind of rework keeps recurring, turn it into a new rule so the standards evolve with the project.
Turning tacit experience into explicit assets is the real value of this approach: AI no longer has to re-guess team habits every time, and the team no longer acts as a parrot. When the five rails—planning, state, types, styles, and structure—are all in place, AI’s React output moves from “looks like it runs” to “ready to merge.”
