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
- 参考文档references/you-dont-need-useeffect.md33.6 KB
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
typekeyword 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
refas a regular prop —React.ComponentPropsalready includesref:function CustomInput(props: React.ComponentProps<'input'>) { return <input {...props} />; } - When exposing imperative APIs, use
useImperativeHandlewith a named function callback - Use
useRefonly for values that don't affect rendering (DOM nodes, timers, IDs)
Performance (React Compiler)
- DO NOT manually use
memo,useMemo, oruseCallback— 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, unlikeuseContext) - Always wrap context consumption in a custom hook with a runtime guard via
useSafeContext - Use
displayNameon all context objects for DevTools debugging
Props & Composition
- PREFER composition over configuration
- AVOID excessive boolean props; prefer expressive APIs
- Use
childrenintentionally; type asReactNode - 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
web-security
Enforce web security and avoid security vulnerabilities.
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.
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.
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.
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.
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`.