AI-Powered React Pitfalls and Solutions Through Five Skills
Discover the common pitfalls when using AI tools for React development—such as over-generation, poor type safety, missing states, and structural chaos—and learn how to resolve them using five specialized skill configurations that enforce project standards and streamline your workflow.
Common Pitfalls When AI Writes React, and How Five Skills Solve Them
When using intelligent coding tools to assist with React development, you might encounter these scenarios: You ask it to add a list component, and it returns a dozen files a few minutes later. You ask it to fix an empty state display, and it takes the opportunity to replace all any types in the component with looser ones. You explicitly mention that the project uses Tailwind, yet it hand-writes a set of inline styles with color: #3b82f6. Every time you start a new conversation, you have to re-paste the project standards again, like a tireless parrot.
The root cause of this pain point is not insufficient AI capability, but rather that team standards are not expressed in a structured way. Prompt instructions are temporary, forgettable, and non-reusable. Through a configurable skill mechanism—defining a skill directory in the project root and describing trigger conditions and execution constraints with structured documents—we can solidify standards as part of the project, allowing the tool to automatically load and enforce them at the appropriate time. The following five skill packages are practices I have refined across numerous React projects, covering the complete chain from requirement clarification to code implementation.
1. Prioritize Planning: Use plan-with-me to Stop AI from Coding Directly
Problem: AI is Too Hasty, and Edge Cases Rely on Luck
When you say “help me write a user list page,” the AI immediately outputs components, routes, API calls, and style files, appearing highly efficient. But look closer: where do the pagination parameters come from? Does the search box need debouncing? When the API fails, should it show an error message or degrade to a skeleton screen? When the list is empty and there are no search conditions, what text should be displayed? These edge cases can only be guessed by the AI based on probability, and if it guesses wrong, you spend more time on rework.
Key Skill Configuration Points
The core of this skill is not “make the AI slow down,” but “make the AI converge uncertainties before taking action.” The description in the frontmatter needs to be strong enough to prevent the model from bypassing it when encountering new features, new pages, or significant changes:
---name: plan-with-medescription: ALWAYS invoke when the user describes a new feature, page, or significant change. Do not write code or produce a plan without this skill.---1. First read existing similar components in the project and summarize existing patterns (directory structure, naming, state management approach).2. List all technical details requiring user confirmation: data sources, loading strategies, empty states, error states, permission boundaries, interaction feedback.3. Output a step-by-step implementation plan including a file list, key interface signatures, and dependency changes.4. Wait for explicit user confirmation before starting to write code.
Why It Works
This skill brings design issues that would only surface during review to the generation stage. More importantly, it prompts the AI to actively read your project’s historical code, reusing existing abstractions rather than reinventing the wheel. In the long run, you will find that the quality of discussions during team requirement reviews also improves, because many ambiguous points have already been forced out by this plan.
2. Type Defense: Prohibit any and Excessive Assertions
Problem: Type System Becomes Useless
When generating code, the AI often takes shortcuts with complex data: the API returns any, event handler parameters are any, and as is used to forcibly eliminate compilation errors. This code runs, but the protection of the type system is completely lost. Later, when a data structure is modified in one place, the compiler cannot provide any hints.
Key Skill Configuration Points
---name: strict-typesdescription: Use when writing or editing any TypeScript file in this project. Enforces type safety rules.---- Prohibit the use of `any`. If third-party library types are missing, use `unknown` with type guards to narrow down.- Prohibit using `as` to assert business data. Only allow it for narrow scenarios like DOM elements where the compiler cannot infer, and require comments explaining the reason.- All component props must define an interface or type. Prohibit implicitly inferred spread attributes passed to child components.- API responses must have independent type definition files, placed in the same directory as runtime validation logic (such as schema validation).
Implementation Advice
Rules alone are not enough; you also need to provide the AI with reference examples. You can attach the path to a “standard component” in the project within the skill document, so the model reads it before writing. This way, the style and naming conventions of the type definitions it outputs will remain consistent with the project, rather than introducing another personal preference.
3. State Prediction: Enforce Coverage of Empty, Error, and Loading States
Problem: Only the Ideal Path is Written
Components generated by AI usually only consider the case where data returns normally. When you ask it to write a list, it gives you a rendered list. The empty states, loading skeletons, request failures, and partial data missing that you didn’t mention are all ignored. When integration testing begins, you find that every list needs to be patched separately.
Key Skill Configuration Points
---name: state-coveragedescription: Use when creating or modifying any data-driven React component.Must explicitly handle the following states, none can be omitted:- loading: Prefer skeleton screens, prohibit full-page spinners.- empty: Distinguish between "no data" and "no filter results" texts.- error: Display the error reason and provide a retry entry, prohibit swallowing exceptions.- success: Handle missing fields, long text truncation, and number formatting.
Advanced Practice
You can further require the AI to extract state judgments into a unified branch structure, rather than scattering ifs in every return. For example, agree on a renderContent() function to centrally handle the four states, while the component body is only responsible for layout. This way, when adding a new state later (such as “no permission”), the scope of changes is controllable.
4. Style Convergence: Prohibit Magic Values and Hand-Written Colors
Problem: Style System is Bypassed
Even if the project has already adopted an atomic CSS solution, the AI will still casually write style={{ color: '#666' }} or margin-top: 37px. Once magic values enter the codebase, theme switching, dark mode, and design specification adjustments all fail.
Key Skill Configuration Points
---name: style-systemdescription: Use whenever writing or modifying React component styles.- Only allow the use of atomic CSS class names agreed upon in the project; prohibit inline style attributes (except for dynamically calculated positions).- Prohibit hexadecimal color values and pixel magic numbers. Use class names corresponding to design tokens for spacing.- Unified use of agreed responsive breakpoints (e.g., sm: md: lg:), no custom media queries allowed.- If the project uses CSS variables, they must be referenced by variable name; prohibit defining local variables inside components.
Effect
This rule seems trivial but has profound implications. It ensures that the interfaces generated by AI are visually consistent with existing pages and avoids the fragmentation problem of “a minor adjustment for each page.” If the team has a design specification document, you can directly reference the document path in the skill, allowing the model to read it before writing styles.
5. Structural Placement: Files Must Be Placed in the Correct Directory
Problem: Files Scattered Everywhere
The AI does not know your directory conventions. It might put a new page in pages/, while your project uses features/ organized by business domain. It might stuff hooks into the same directory as components, while your specification requires all hooks to be centralized under hooks/. After writing a feature, you have to spend time moving a dozen files to their correct positions and changing import paths.
Key Skill Configuration Points
---name: project-structuredescription: Always apply when creating any new file or directory in the project.Directory conventions:- Business modules go in `src/features/<domain>/`, with each module containing components, hooks, api, and types subdirectories.- Globally shared components go in `src/shared/components/`.- Route configurations are uniformly declared under `src/app/routes/`, and page components themselves do not define routes.- Before creating a new file, check if a file with the same name already exists in the target directory to avoid duplicate creation.
Additional Benefits
When the AI strictly follows directory conventions, its import paths become more accurate, reducing build failures caused by path errors. More importantly, when new members join the team, whether the code is written by humans or AI, the structure is unified, significantly reducing cognitive costs.
6. Collaboration: Forming a Pipeline with Five Skills
Individual skills solve single-point problems; combined, they form a complete constraint pipeline. The recommended execution order is:
- Planning Stage:
plan-with-meforces requirement clarification and outputs a plan for confirmation. - Generation Stage:
strict-typesandstyle-systemtake effect in parallel to ensure type and style compliance. - Refinement Stage:
state-coveragechecks whether all four states are complete. - Placement Stage:
project-structureensures every file is in the right place.
In practice, it is recommended to write the description of these five skills as specifically as possible, including clear trigger words (such as “new feature,” “modify styles,” “create new file”) so the model can accurately determine when to load which skill. If too many skills cause loading conflicts, you can merge related rules into one skill, using sections to distinguish scenarios.
7. From Verbal Instructions to Engineering Constraints
In retrospect: In the past, we relied on repeated instructions to correct AI, which was essentially “manual runtime validation.” The skill mechanism moves validation ahead to “compile-time”—rules are written in files and take effect automatically with every generation. This brings not only less talking, but also auditable, iterable, and shareable standard assets.
For team collaboration scenarios, these skill files should be included in version control and evolve with the project. When standards change, you only need to update a Markdown file, and the behavior of the entire team (including AI) aligns immediately. This is more efficient than any training or documentation.
One last piece of advice: Do not stuff all standards into skills at once. Start with the highest-frequency, quality-impacting pain points, such as type safety and the planning process, verify effectiveness, and then gradually expand. The value of skills lies not in quantity, but in whether each rule truly reduces rework.
