5 AI Coding Skills to Tame Messy React Code

    This article explains why AI-generated React code tends to degrade over time and presents five declarative, repository-based skills that keep it consistent. You will learn how to enforce planning before generation, maintain a lightweight project state index, validate design tokens and directory ownership, and run a pre-delivery checklist. The focus is on moving team conventions from verbal reminders into versioned, machine-enforceable rules that improve review quality and reduce rework.

    1. The Problem Is Not That AI Can’t Write React, It’s That It Doesn’t Know Your React

    The first version of AI-generated React code is often impressive: clean structure, sensible naming, running within minutes. Stretch the timeline to half a day, though, and blood pressure starts to climb. The symptoms are remarkably consistent:

    • Component props have no type definitions, or any and type assertions are used to bypass checks;
    • A client directive is added regardless of the runtime, breaking server component boundaries at will;
    • Styles contain one-off magic values and random colors, bypassing the project’s shared design tokens;
    • Files land in the wrong place, with page-level components, routes, and business modules mixed together, so directory semantics rot quickly;
    • Edge cases are collectively missing: empty data, loading, failed requests, debouncing, and race conditions are all ignored.

    The root cause is not model capability but missing context. Team conventions live in people’s memory, in review comments, and in the corners of documents, but they do not exist in the repository in a form that can be automatically loaded and machine-enforced. So every new session, developers have to paste the project conventions again, acting as a human repeater.

    The fix is to migrate conventions from verbal reminders to declarative constraints inside the repository. A common industry approach is to maintain a conventions folder at the project root (for example, .claude/skills), where each skill is a Markdown rule set with a name and a trigger description. When a task’s semantics match a description, the rules are automatically loaded into context. The value is threefold: versionable (conventions are reviewed and rolled back alongside code), reusable (new members need no verbal handover), and composable (multiple skills can match at once and cover for each other).

    The five skills below cover the full chain of think it through, put it in the right place, style it correctly, keep it in sync, and self-check before delivery.

    2. Skill One: Plan First, Eliminate Design Flaws Before Generation

    Example trigger description:

    1. name: plan-with-me
    2. description: Must be loaded when the user describes a new feature, a new page, or a larger change;
    3. output of implementation code is forbidden before clarification and plan confirmation are complete.

    Impatience is a common flaw of generative tools: one sentence of requirements, and a dozen files are immediately scaffolded. The planning skill inserts a mandatory gate between “requirements” and “code”, requiring three things first:

    1. Clarify: ask about interaction details one by one, including debounce and throttle durations, empty-state copy, loading and failure branches, pagination and sorting rules, permission differences, and analytics definitions;
    2. Research: read the codebase first, find similar existing implementations, and reuse their abstractions and naming instead of starting a parallel set;
    3. Plan: output the file list, type signatures, state ownership (local state / context / server state), and test points, then wait for confirmation before writing anything.

    Example output:

    1. Plan:
    2. 1. features/order/components/OrderTable.tsx — presentational only, props explicitly declared
    3. 2. features/order/hooks/useOrderQuery.ts — unified request and cache keys
    4. 3. Empty/error states reuse components/feedback/*
    5. 4. Search input debounced at 300ms, request cancellation handled by AbortController
    6. I'll write the code after you confirm.

    The benefit is that review cost moves earlier: most rework comes from “misunderstood requirements”, not coding errors.

    3. Skill Two: A Project State Index, So AI Stops Stuffing Code Into an “Old Map”

    After components move, directories are reorganized, or dependencies are swapped, the model’s memory is static, and it will still write files to deprecated paths. The solution is to maintain a minimal project state index, such as PROJECT-STATE.md, that records only facts that change:

    1. name: update-project-memory
    2. description: Must be loaded after any file/component/route/API/design token is added, deleted, renamed, or migrated.
    1. ## Directory conventions
    2. - Page level: src/features/<domain>/pages
    3. - Shared presentation: src/components/ui
    4. ## Change log
    5. - 2024-xx-xx OrderTable moved from components/ to features/order/components
    6. - 2024-xx-xx primary color token color.primary renamed to token.brand.500

    The key constraint is “write facts only, no opinions”, incrementally updating the relevant line on each change. Other skills read the index before executing, which noticeably improves location accuracy and incidentally produces an architecture change log that is friendly to new members.

    4. Skill Three and Skill Four: Style Token Validation and Directory Ownership Validation

    The style skill blocks magic values and arbitrary colors, requiring colors, spacing, radii, and font sizes to come from design tokens, and responsive breakpoints to use shared variables:

    1. // Not recommended: one-off values and hardcoded colors
    2. <div style={{ color: '#3b82f6', marginTop: 37 }} />
    3. // Recommended: semantic tokens
    4. <div className="text-brand-500 mt-9 rounded-lg" />

    The directory ownership skill turns “where does this go” into a decidable rule: page components go in features/<domain>/pages, cross-domain reuse goes in components/ui, requests and cache keys are centralized in the hooks or api layer, and the route table is registered in one place. Rules should be written in a mechanically verifiable form, combined with static checks and directory boundary constraints, so violations are blocked before commit.

    5. Skill Five: A Pre-Delivery Self-Check List

    The last skill triggers as the task wraps up and verifies a fixed list item by item: types are complete (no any, no unnecessary assertions), accessibility (semantic tags, keyboard reachability, contrast), performance (list virtualization, avoiding needless re-renders), error and empty states, tests and docs in sync, and whether the state index has been updated. It outputs a short self-check conclusion, with failed items explicitly listed rather than silently ignored.

    6. Implementation Advice

    • Keep skill files short, imperative, and decidable; avoid long prose that dilutes attention;
    • Write descriptions that state clearly “when it must be loaded”; trigger precision determines success or failure;
    • Combine with static checks, type checks, and pipeline gates to form a two-layer defense of “generation-time constraints plus commit-time backstop”;
    • Let conventions evolve with iterations, writing each review consensus back into the skills to form a positive loop.

    If your team already collaborates in a cloud development environment, these rule files can be managed centrally in the code repository, and general cloud capabilities such as container platforms, log services, and monitoring alerts can be used to observe constraint hit rates and rework rates. Engineering practice at Baidu AI Cloud also shows that making implicit conventions explicit and executable is a key step toward more stable AI-assisted coding.