跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 react

React

综合 反应开发指南涵盖组件架构,钩子,状态管理,TypeScript集成,使用效果模式,并测试与Vitest. 在创建 React 组件,自定义钩子,管理状态,或任何前端 React 代码时使用. 对19+反应开发至关重要. 不要用于回放原生,非回放框架(Vue, Svelte, Solid),或者只用于后端的Node.js代码.

9 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

综合 反应开发指南,涵盖组件架构、钩子、状态管理、TypeScript集成、使用效果模式,以及与Vitest的测试

何时用

(并避免)使用效果,改为`参考/使用效果-patters.md'

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React Development Guide、Quick Start、Core Principles、Extend native element props、Quick Reference Tables、State Management Hierarchy。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/best-practices.md、references/useeffect-patterns.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Comprehensive React development guide covering component architecture, hooks, state management, TypeScript integration, useEffect patterns, and testing with Vitest. Use when creating React components, custom hooks, managing state, or any frontend React code. Essential for React 19+ development. Don't use for React Native, non-React frameworks (Vue, Svelte, Solid), or backend-only Node.js code.

React Development GuideQuick StartCore PrinciplesExtend native element propsQuick Reference TablesState Management HierarchyuseEffect Decision TreeWhen You DO Need EffectsWhen You DON'T Need EffectsTypeScript IntegrationCustom Hooks GuidelinesComponent Architecture Pattern

· allowed-tools:Read, Grep, Glob

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
react
description
Comprehensive React development guide covering component architecture, hooks, state management, TypeScript integration, useEffect patterns, and testing with Vitest. Use when creating React components, custom hooks, managing state, or any frontend React code. Essential for React 19+ development. Don't use for React Native, non-React frameworks (Vue, Svelte, Solid), or backend-only Node.js code.
allowed-tools
Read, Grep, Glob实验字段,支持情况取决于客户端;字段声明本身不会授予工具权限。
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 2
  • references/best-practices.md
  • references/useeffect-patterns.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「react」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-bfa7e9720c12a478-%E5%8F%8D%E5%BA%94.html
请存为 .cursor/skills/react/SKILL.md 或 .claude/skills/react/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/ronaldocutrim/skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/ronaldocutrim/skills' --list

npx skills add 'https://github.com/ronaldocutrim/skills' --skill 'react'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: react description: Comprehensive React development guide covering component architecture, hooks, state management, TypeScript integration, useEffect patterns, and testing with Vitest. Use when creating React components, custom hooks, managing state, or any frontend React code. Essential for React 19+ development. Don't use for React Native, non-React frameworks (Vue, Svelte, Solid), or backend-only Node.js code. allowed-tools: Read, Grep, Glob metadata: author: Pedro Nauck github: https://github.com/pedronauck repository: https://github.com/pedronauck/skills --- # React Development Guide This skill provides comprehensive guidelines, patterns, and best practices for React development in this project. ## Quick Start 1. **Best Practices**: For component architecture, state management, and TypeScript integration, read `references/best-practices.md` 2. **Element wrappers**: If a component renders a single native element (`button`, `input`, `a`, …), extend that element’s props (`React.ComponentProps<"…">`) and spread `...props` — see **Extend native element props** below and `references/best-practices.md` → *Extending HTML Elements*. 3. **useEffect Patterns**: For understanding when to use (and avoid) useEffect, read `references/useeffect-patterns.md` 4. **Data Fetching**: For TanStack Query patterns, use the `tanstack` skill 5. **Forms**: For form handling with TanStack Form, use the `tanstack` skill ## Core Principles - **Functional Components Only**: Use functional components exclusively - class components are legacy - **Single Responsibility**: Keep components small and focused on a single purpose - **Separation of Concerns**: Extract behavior logic into custom hooks, keep components focused on rendering - **Feature-Based Organization**: Co-locate related files by feature, not by type - **React 19+ Features**: Embrace modern React features (`use()`, Actions, `useOptimistic()`) ## Extend native element props **Default rule for wrappers:** whenever a component’s root output is a **single native element**, its props interface MUST extend that element’s intrinsic props — same contract as shadcn/ui-generated primitives. Callers keep access to `aria-*`, `data-*`, `onClick`, `disabled`, etc., without bespoke passthrough lists. **Do this:** | Requirement | Detail | | ------------- | ------ | | Base type | `interface XProps extends React.ComponentProps<"button">` (or `"input"`, `"a"`, `"div"`, …) | | Spreading | Destructure your custom fields, then `{...props}` (and merged `className`) onto the DOM node | | Ref | Use `React.forwardRef` and the matching element ref type when refs are needed | ```typescript interface TextFieldProps extends React.ComponentProps<"input"> { label: string; error?: string; } function TextField({ label, error, className, ...props }: TextFieldProps) { return ( {label} {error ? {error} : null} ); } ``` **Variants + CVA:** if you use `class-variance-authority`, combine intrinsic props with `VariantProps` (often `extends React.ButtonHTMLAttributes`). Follow the **`shadcn`** skill patterns. **Deep dive:** `references/best-practices.md` → *Extending HTML Elements*. ## Quick Reference Tables ### State Management Hierarchy | Priority | Tool | Use Case | |----------|------|----------| | 1 | `useState`/`useReducer` | Component-specific UI state | | 2 | Zustand | Shared client state across components | | 3 | TanStack Query | Server state and data synchronization | | 4 | URL state | Shareable application state (TanStack Router) | ### useEffect Decision Tree | Situation | DON'T | DO | |-----------|-------|-----| | Derived state from props/state | `useState` + `useEffect` | Calculate during render | | Expensive calculations | `useEffect` to cache | `useMemo` | | Reset state on prop change | `useEffect` with `setState` | `key` prop | | User event responses | `useEffect` watching state | Event handler directly | | Notify parent of changes | `useEffect` calling `onChange` | Call in event handler | | Fetch data | `useEffect` without cleanup | `useEffect` with cleanup OR TanStack Query | ### When You DO Need Effects - Synchronizing with **external systems** (non-React widgets, browser APIs) - **Subscriptions** to external stores (use `useSyncExternalStore` when possible) - **Analytics/logging** that runs because component displayed - **Data fetching** with proper cleanup (or use TanStack Query) ### When You DON'T Need Effects 1. **Transforming data for rendering** - Calculate at top level, re-runs automatically 2. **Handling user events** - Use event handlers, you know exactly what happened 3. **Deriving state** - Just compute it: `const fullName = firstName + ' ' + lastName` 4. **Chaining state updates** - Calculate all next state in the event handler ## TypeScript Integration ```typescript // CORRECT: Type props directly (never use React.FC) interface BrandButtonProps { variant: "primary" | "secondary"; children: React.ReactNode; } function BrandButton({ variant, children }: BrandButtonProps) { return {children}; } // When wrapping a native element, extend its props — see "Extend native element props" above interface IconButtonProps extends React.ComponentProps<"button"> { icon: React.ReactNode; } ``` ## Custom Hooks Guidelines - Extract non-visual logic into custom hooks - Keep hooks focused on single purpose - Use clear naming: `useXxx` pattern - Return arrays for state-like hooks, objects for complex returns ```typescript // State-like hook returns array function useToggle(initial = false) { const [value, setValue] = useState(initial); const toggle = useCallback(() => setValue((v) => !v), []); return [value, toggle] as const; } // Complex hook returns object function useUser(id: string) { const query = useQuery({ queryKey: ["user", id], queryFn: () => fetchUser(id) }); return { user: query.data, isLoading: query.isLoading, error: query.error, refetch: query.refetch, }; } ``` ## Component Architecture Pattern ```typescript // CORRECT: Hook handles all logic, component handles rendering function useIssueSearch(projectId: string) { const [query, setQuery] = useState(""); const [filters, setFilters] = useState({}); const issues = useQuery({ queryKey: ["issues", projectId, query, filters], queryFn: () => searchIssues(projectId, query, filters), }); return { query, setQuery, filters, setFilters, issues: issues.data ?? [], isLoading: issues.isLoading, }; } function IssueList({ projectId }: { projectId: string }) { const { query, setQuery, issues, isLoading } = useIssueSearch(projectId); return (
{isLoading ? : }
); } ``` ## File Naming Conventions | Type | Pattern | Example | |------|---------|---------| | Components | kebab-case.tsx | `user-avatar.tsx` | | Hooks | use-kebab-case.ts | `use-user-data.ts` | | Utilities | camelCase.ts | `formatDate.ts` | | Types | types.ts | `types.ts` | | Tests | *.test.tsx | `user-avatar.test.tsx` | ## Testing with Vitest ```typescript import { describe, it, expect, vi } from "vitest"; import { render, screen } from "@testing-library/react"; import { renderHook, act } from "@testing-library/react"; describe("MyComponent", () => { it("renders correctly", () => { render(); expect(screen.getByText("Hello")).toBeInTheDocument(); }); }); describe("useMyHook", () => { it("returns expected value", () => { const { result } = renderHook(() => useMyHook()); expect(result.current.value).toBe(expected); }); }); ``` ## Validation Checklist Before finishing a task involving React: - [ ] Components are functional and follow single responsibility principle - [ ] Behavior logic is extracted into custom hooks - [ ] TypeScript props are typed directly (not using `React.FC`); native wrappers extend `React.ComponentProps<"…">` (or `ButtonHTMLAttributes` + variants per `shadcn` skill) and forward `...props` - [ ] State management follows the hierarchy (local -> Zustand -> TanStack Query -> URL) - [ ] useEffect is only used for external system synchronization - [ ] Error boundaries are in place for error handling - [ ] Loading and error states are handled - [ ] Accessibility requirements are met (semantic HTML, keyboard navigation) - [ ] Tests are written for components and hooks - [ ] Run `pnpm run lint`, `pnpm run typecheck`, and `pnpm run test` ## Detailed References For comprehensive guidance, consult these reference files: - `references/best-practices.md` - Component architecture, TypeScript, state management, React 19+ features, testing patterns - `references/useeffect-patterns.md` - When to use/avoid useEffect, anti-patterns, and better alternatives

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…