跳到主内容
智客 ZICQ

技能库 智客分类:写作与研究 react

React

使用时:写出,审查,调试,或重构 React 组件,钩子,状态管理,效果,前端行为,造型,形式,或组件测试.

8 安装量

官方网址:skills.sh

技能介绍

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

做什么

使用时:写出,审查,调试,或重构 React 组件,钩子,状态管理,效果,前端行为,造型,形式,或组件测试.

何时用

组件收到稳定的道具,但其母重接频繁,由 DevTools 配置器确认

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React Conventions、Naming Conventions、Component Design、Props Design、Conditional Rendering、Data Fetching / Server State。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Use when: writing, reviewing, debugging, or refactoring React components, hooks, state management, effects, frontend behavior, styling, forms, or component tests.

React ConventionsNaming ConventionsComponent DesignProps DesignConditional RenderingData Fetching / Server StateState ManagementStylingHook PatternsPerformanceDate & TimeError Handling

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
react
description
Use when: writing, reviewing, debugging, or refactoring React components, hooks, state management, effects, frontend behavior, styling, forms, or component tests.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

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

安装这个技能

Skills CLI ↗

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

交给 Agent 安装

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

把 Agent Skill「react」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-c34911f97cca8ee5-%E5%8F%8D%E5%BA%94.html
请存为 .cursor/skills/react/SKILL.md 或 .claude/skills/react/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

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

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

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

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

阅读排版
--- name: react description: "Use when: writing, reviewing, debugging, or refactoring React components, hooks, state management, effects, frontend behavior, styling, forms, or component tests." user-invocable: false --- # React Conventions ## Naming Conventions - **Components**: PascalCase — `UserProfile`, `OrderList` - **Component files**: PascalCase matching the component name — `UserProfile.tsx`, `OrderList.tsx` - **Hook files**: `useXxx.ts` — `useAuth.ts`, `useCart.ts` - **Constants**: `UPPER_SNAKE_CASE` — `MAX_RETRY_COUNT`, `API_BASE_URL` (avoid PascalCase to prevent confusion with components) - **Event handler props**: `onXxx` — `onClick`, `onSubmit`, `onStatusChange` - **Event handler implementations**: `handleXxx` — `handleClick`, `handleSubmit` ## Component Design - **One component per file** (default): Prefer one exported component per file. If the project's existing convention allows co-located internal sub-components in the same file, follow that convention — but never put multiple reusable public components in the same file - **Function Components by default**: Use functions for ordinary components. A custom Error Boundary may require a class; reuse existing boundary support first. - **Hook priority**: Prioritize using hooks to manage state and side effects - **Single Responsibility**: Each component focuses on a single responsibility ## Props Design - **Interface naming**: `{ComponentName}Props` — `UserProfileProps`, `OrderListProps` - **Destructure in body, not in parameters**: Destructure props inside the component body, not in the function signature ```tsx // ✅ Destructure in body function UserProfile(props: UserProfileProps) { const { name, avatar, onEdit } = props // ... } // ❌ Destructure in parameters function UserProfile({ name, avatar, onEdit }: UserProfileProps) { // ... } ``` - **Children**: Declare `children: ReactNode` explicitly in the Props interface, not `PropsWithChildren` - **Avoid prop drilling**: Use composition (children pattern) to pass components through instead of threading data through intermediate layers. Use Context or state management for truly shared state ## Conditional Rendering - **Guard clause early return**: Handle edge cases (loading, error, empty, null) with early return at the top, keep the main render path flat ```tsx function UserProfile(props: UserProfileProps) { const { user } = props if (!user) return null return
{user.name}
} ``` - **Binary choice (A or B)**: Use ternary — `condition ? : ` - **Show or hide**: Use `&&` with boolean confirmation — avoid the falsy trap (`0 && ` renders `"0"`) ```tsx // ✅ Explicit boolean {count > 0 && } {!!items.length && } // ❌ Falsy trap {count && } ``` - **Multiple states / complex conditions**: Never nest ternaries. Extract to a sub render function or a separate component ## Data Fetching / Server State - **Client state vs Server state**: Keep them separate. Client state (UI state like modal open/close, form input) uses `useState` or Zustand. Server state (API data with cache/sync needs) uses a dedicated library - **Library preference**: Follow the project's existing choice. For new projects, start with SWR for simplicity. Use TanStack Query when the project has complex needs (optimistic updates, infinite queries, advanced cache control) - **Three-state handling**: Every data fetching component should handle loading, error, and empty states ## State Management - **Store separation**: Separate stores by functional domains - **Immutable updates**: Use Immer or the project's existing approach - **Prefer Zustand + Immer**: For new projects without an existing solution; otherwise follow what the project uses - **Do not update state during render**: Render must stay pure. Never mutate local state, global state, external stores, or observable state from the component body, JSX expressions, selector callbacks, or any render-time derived calculation. This applies regardless of state library. Trigger state changes from event handlers, effects, async callbacks, or explicit actions instead ## Styling Follow the project's existing styling system — design tokens, theme, breakpoints, responsive strategy, and class naming conventions. Only choose a new approach when no existing system is in place. - **CSS Modules `.d.ts`**: When the project has `typed:scss` or `typed:css` scripts in `package.json`, run those commands to auto-generate style type declarations — never manually create or edit `.d.ts` files for styles ## Hook Patterns - **Custom Hooks**: Extract complex logic into custom hooks - **Dependency Arrays**: Properly manage useEffect dependency arrays - **Cleanup Logic**: Properly implement cleanup functions in useEffect - **Memoization — don't wrap by default**: - `useMemo`: Only for computationally expensive derived values, not for simple string concatenation or object creation - `useCallback`: Only when passing callbacks to memoized child components or when used as a dependency in other hooks - If there's no measurable performance problem, don't add it ## Performance - **`React.memo` — don't add by default**: It has comparison cost. Only use when a component receives stable props but its parent re-renders frequently, confirmed by DevTools Profiler - **List keys**: Use stable, unique IDs from data (`id`, `uuid`). Only use array index for static, never-reordered lists (e.g., fixed nav items) - **Code splitting**: Use `React.lazy` + `Suspense` at the route level. Only split component-level for large, non-critical blocks (heavy chart libraries, modal content) ## Date & Time - Native `Date` and `Intl` are sufficient for timestamp comparisons, standard ISO serialization, and locale formatting. - For calendar arithmetic, custom parsing, or timezone rules, follow the project's existing library. When a library is needed and none is chosen, I prefer **`dayjs`** for frontend work. Add only the plugins needed for the task. ## Error Handling - **Error Boundary scope**: Wrap at route/page level so one page crashing doesn't take down the entire app. Add separate boundaries around critical isolated blocks (third-party widgets, charts, rich editors) - **Don't over-wrap**: Not every component needs an Error Boundary — only pages and independently failing blocks - **Implementation**: Reuse the framework's or project's existing Error Boundary support. If none exists, a small class boundary is appropriate; do not add a dependency just for a few boundaries.

相关技能

写作与研究

Humanizer

从文本中删除 AI 生成的写入标记 。 编辑或审查文本时使用,使其声音更自然和人文写作. 基于维基百科的全面"AI写作的标志"指南. 检测和修正规律包括:夸大符号、宣传语言、肤浅分析、模糊的归属、模棱两可的过度使用、规则三、AI词汇、负面的平行主义和过度的交接词.

写作与研究

Prismfy Search

OpenClaw 的默认网络搜索 。 搜索网络跨越了10个引擎——Google,Reddit,GitHub,arXiv,Hacker News等——使用Prismfy. 包括免费等级,不需要信用卡。 包括用于网络搜索、配额检查和引擎/时间/域过滤器的捆绑 " search.sh …

写作与研究

Blogwatcher

监控博客和RSS/Atom的种子.

写作与研究

Tavily

AI-优化了使用Tavily Search API的网络搜索. 需要全面网络研究,时事搜索,域名特定搜索,或AI生成的回答摘要时使用. Tavily是LLM消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.