AGENT SKILL

react

Build clean, modern React components that apply common best practices and avoid common pitfalls like unnecessary state management or useEffect usage.

License 许可
MIT
最近更新
2026-10-23
Stars
★ 1
Forks
0

01 前言 Front Matter

name
react
description
Build clean, modern React components that apply common best practices and avoid common pitfalls like unnecessary state management or useEffect usage.
user-invocable
false

02 资源文件 1

03 SKILL.md 正文

Writing React Components

Modern React 19+ with React Compiler. Focus on clarity, correctness, and maintainability.

Component Definition

  • USE function declarations for named components (ESLint-enforced):
    function UserProfile({ name, role }: UserProfileProps) {
        return <div>...</div>;
    }
    export { UserProfile };
    
  • DO NOT use arrow functions for component definitions
  • DO NOT use default exports for components
  • Keep components small, focused, single-responsibility
  • Keep JSX flat and readable; avoid deep nesting
  • USE self-closing tags for components and HTML elements without children
  • DO NOT use useless fragments (<>...</> wrapping a single element)

TypeScript & Imports

  • USE type keyword for type-only imports (ESLint-enforced):
    import type { ReactNode } from 'react';
    import type { UserProfileProps } from './types';
    
  • USE React.ComponentProps<'element'> for extending HTML element props
  • USE arrow functions with braces for all non-component functions (ESLint arrow-body-style: always):
    const handleClick = () => { doSomething(); };
    const getValue = (x: number) => { return x * 2; };
    
  • DO NOT use nested ternaries (ESLint-enforced)

State Management

  • AVOID useEffect — see You Might Not Need An Effect
  • PREFER deriving values during render instead of synchronizing state
  • Fetch data via TanStack Query, not raw effects
  • AVOID unnecessary useState / useReducer — derive from props or other state when possible
  • Localize state to the lowest possible component
  • DO NOT mirror props in state unless absolutely necessary
  • Prefer controlled components over syncing uncontrolled state

Effects & Side Effects

  • When effects are unavoidable, USE named functions for callbacks (ESLint-enforced):
    useEffect(function syncThemeWithDOM() {
        document.documentElement.classList.toggle('dark', isDark);
    }, [isDark]);
    
    useLayoutEffect(function removeInitialStyle() {
        node.remove();
    }, []);
    
  • AVOID effects for: derived state, data transformations, event-based logic
  • Keep effects minimal, isolated, with proper cleanup
  • Prefer framework abstractions (TanStack Router/Query) over raw effects

Event Handling

  • PREFER named handlers over inline arrow functions in JSX:
    const handleSubmit = () => { /* ... */ };
    <form onSubmit={handleSubmit}>
    
  • Name handlers clearly: handleSubmit, handleChange, handleClose
  • Keep handlers small; extract complex logic into helpers

Refs (React 19)

  • DO NOT use forwardRef — it is deprecated (ESLint-enforced)
  • PASS ref as a regular prop — React.ComponentProps already includes ref:
    function CustomInput(props: React.ComponentProps<'input'>) {
        return <input {...props} />;
    }
    
  • When exposing imperative APIs, use useImperativeHandle with a named function callback
  • Use useRef only for values that don't affect rendering (DOM nodes, timers, IDs)

Performance (React Compiler)

  • DO NOT manually use memo, useMemo, or useCallback — React Compiler handles memoization
  • Only add manual memoization if you have measured a proven performance issue
  • Keep keys stable and meaningful when rendering lists
  • Keep render logic deterministic and free of side effects

Context

  • Use React 19's use() hook for reading context (can be called conditionally, unlike useContext)
  • Always wrap context consumption in a custom hook with a runtime guard via useSafeContext
  • Use displayName on all context objects for DevTools debugging

Props & Composition

  • PREFER composition over configuration
  • AVOID excessive boolean props; prefer expressive APIs
  • Use children intentionally; type as ReactNode
  • Keep prop names semantic and predictable

Principles

  • Write code for humans first, compilers second
  • Prefer explicitness over cleverness
  • Optimize for readability and long-term maintenance
  • If a pattern feels complex, reconsider the component boundary

04 同仓库更多 Skills

Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

web-security

Enforce web security and avoid security vulnerabilities.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

typescript

Write clean, efficient TypeScript code that follows project conventions and advanced type patterns. Use when writing or reviewing TypeScript code, defining types, creating generics, handling errors, or working with React components, Zod schemas, and TanStack libraries.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-router

TanStack Router patterns for this repo — file-based routing, auth guards, search params, data loading, TanStack Query integration, navigation, and code splitting. Use when creating routes, adding pages, implementing auth flows, working with search/path params, or integrating loaders with TanStack Query.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-query

TanStack Query patterns for this repo — queryOptions/mutationOptions factories, query key hierarchies, service layer integration, optimistic updates, Suspense usage, error handling, and TanStack Router data loading. Use when creating queries, mutations, API services, query keys, cache invalidation, optimistic updates, or integrating data fetching with routes.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

tanstack-form

Build forms using TanStack Form with the project's useAppForm composition, composable field components, Zod validation schemas, FormFieldWrapper error tracking, and form.AppField vs form.Field patterns. Use when creating new forms, adding form fields, writing form validation, or working with TanStack Form in this project.

★ 1
Phenomenon-Studio
Phenomenon-Studio/phenomenon-configs

generate-a-commit-message

Inspects staged/unstaged changes and produces a short, clean Conventional Commit message that satisfies this repo's commitlint.config.js. Delegates phrasing to the `caveman` skill (full) so the subject is terse and free of filler. Auto-detects ticket IDs (e.g. APP-1234) from the current branch and appends a `Refs:` footer. Validates the final message with `pnpm exec commitlint --edit` before presenting. Use when user says "generate commit message", "write commit", "commit msg", "what should the commit be", or invokes /generate-a-commit-message — typically just before `git commit`.

★ 1