做什么
反应 18/19 模式,包括钩子学科,服务器/客户端组件边界,悬时+出错边界,形式动作,取出数据,状态管理决策树,以及可访问性第一构成
技能库 智客分类:写作与研究 react-patterns
反应出 第18/19个模式,包括钩子纪律,服务器/客户端组件边界,悬时+出错边界,组成动作,取取出数据,状态管理决策树,以及可访问性第一构成. 写入或审查 React 组件时使用 .
官方网址:skills.sh
先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。
反应 18/19 模式,包括钩子学科,服务器/客户端组件边界,悬时+出错边界,形式动作,取出数据,状态管理决策树,以及可访问性第一构成
写入或审查反应组件
按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React Patterns、When to Activate、Core Principles、1. Render is a Pure Function of Props and State、2. Side Effects Outside Render、3. Composition Over Inheritance。
文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。
React 18/19 patterns including hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, data fetching, state management decision trees, and accessibility-first composition. Use when writing or reviewing React components.
React PatternsWhen to ActivateCore Principles1. Render is a Pure Function of Props and State2. Side Effects Outside Render3. Composition Over InheritanceHooks DisciplineState Location Decision TreeServer / Client Components (RSC)Suspense + Error BoundariesFormsReact 19 form actions (preferred for new code)
来源分类:skills.sh agent-skill
namereact-patternsdescription具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗
先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。
复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。
把 Agent Skill「react-patterns」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-33e458baba79b514-%E5%8F%8D%E5%BA%94%E6%A8%A1%E5%BC%8F.html 请存为 .cursor/skills/react-patterns/SKILL.md 或 .claude/skills/react-patterns/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。
npx skills add 'https://github.com/affaan-m/ecc' --list
npx skills add 'https://github.com/affaan-m/ecc' --skill 'react-patterns'
CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。
{state.error}
} ); } ``` ### Controlled inputs Use controlled when the value drives other UI, formats on every keystroke, or implements real-time validation. ### Complex forms For multi-step forms, dynamic field arrays, or cross-field validation: use a library (React Hook Form, TanStack Form). Roll-your-own state management for forms past trivial complexity is a maintenance trap. ## Data Fetching Decision Matrix | Need | Tool | |---|---| | Per-request data in Next.js App Router | RSC `await fetch()` | | Client-side cache + mutations + invalidation | TanStack Query | | Lightweight client cache + revalidation | SWR | | Real-time subscriptions | Server-Sent Events, WebSockets, or the lib's subscription API | | One-off fire-and-forget | `fetch()` in an event handler | Avoid `useEffect` + `fetch` for application data — race conditions, no cache, no retry, no Suspense integration. ## Composition Recipes ### Slot via `children` ```tsx {content} ``` ### Named slots ```tsx } sidebar={}> ``` ### Compound components (shared state via Context) ```tsx Profile Settings ``` ### Render prop / function-as-child Useful when the parent needs to pass parameters to the rendered output: ```tsx {({ data, isLoading }) => isLoading ? : } ``` Modern alternative: a hook (`useData(id)`) returning the same shape — usually cleaner. ## Performance ### When `React.memo` Actually Helps Wrap a component in `React.memo` only when: 1. It re-renders frequently 2. Its props are usually the same between renders 3. Its render is measurably expensive `React.memo` adds an equality check on every render. If props differ on most renders, the check is pure overhead. ### Avoiding Render Cascades - Lift state down rather than up where possible - Split context: one context per concern, so a change to `themeContext` does not re-render auth consumers - Use `useSyncExternalStore` for external state libraries — required for safe concurrent rendering ### Lists - Provide stable `key` props (database id, not array index) - Virtualize long lists with `@tanstack/react-virtual` or `react-window` once visible item count exceeds ~50 with non-trivial rows ## Accessibility-First Composition - Always render semantic HTML (``, ``, ``, ``) before reaching for `role` attributes - Every interactive element must be reachable by keyboard - Form inputs need labels — `` or `aria-label` if visually labeled by an icon - Manage focus on route changes and modal open/close - Run `axe` in component tests (see [skills/react-testing](../react-testing/SKILL.md)) - Cross-link: [skills/accessibility/SKILL.md](../accessibility/SKILL.md) covers WCAG criteria and pattern libraries ## Routing This skill is router-agnostic. The patterns above work with React Router, TanStack Router, Next.js App Router, Remix Router. Router-specific patterns (loaders, actions, nested layouts) follow the router's documentation — those are framework concerns layered on top of React core. ## Out of Scope (Pointer Sections) - **Next.js specifics**: App Router data loading, Route Handlers, Middleware, Parallel Routes — separate concern, use Next.js docs - **React Native**: Platform-specific patterns differ enough to warrant a separate `react-native-patterns` skill (not present yet) - **Remix**: Loader/action conventions overlap with RSC but follow Remix docs ## Related - Rules: [rules/react/](../../rules/react/) — coding-style, hooks, patterns, security, testing - Skills: [react-performance](../react-performance/SKILL.md) for the Vercel-derived performance ruleset, [frontend-patterns](../frontend-patterns/SKILL.md) for cross-framework UI concerns, [accessibility](../accessibility/SKILL.md), [angular-developer](../angular-developer/SKILL.md) for framework comparison - Agents: `react-reviewer` for code review, `react-build-resolver` for build/bundler errors - Commands: `/react-review`, `/react-build`, `/react-test` ## Examples ### Custom hook for debounced search ```tsx function useDebounce(value: T, delay = 300): T { const [debounced, setDebounced] = useState(value); useEffect(() => { const id = setTimeout(() => setDebounced(value), delay); return () => clearTimeout(id); }, [value, delay]); return debounced; } function SearchBox() { const [query, setQuery] = useState(""); const debounced = useDebounce(query, 300); const { data } = useQuery({ queryKey: ["search", debounced], queryFn: () => searchApi(debounced), enabled: debounced.length > 0, }); return ( <> setQuery(e.target.value)} /> ); } ``` ### Optimistic UI with React 19 `useOptimistic` ```tsx "use client"; import { useOptimistic } from "react"; export function MessageList({ messages }: { messages: Message[] }) { const [optimistic, addOptimistic] = useOptimistic( messages, (state, newMessage: Message) => [...state, newMessage], ); async function send(formData: FormData) { const text = String(formData.get("text")); addOptimistic({ id: "pending", text, sender: "me" }); await saveMessage(text); } return ( <>写作与研究
从文本中删除 AI 生成的写入标记 。 编辑或审查文本时使用,使其声音更自然和人文写作. 基于维基百科的全面"AI写作的标志"指南. 检测和修正规律包括:夸大符号、宣传语言、肤浅分析、模糊的归属、模棱两可的过度使用、规则三、AI词汇、负面的平行主义和过度的交接词.
写作与研究
OpenClaw 的默认网络搜索 。 搜索网络跨越了10个引擎——Google,Reddit,GitHub,arXiv,Hacker News等——使用Prismfy. 包括免费等级,不需要信用卡。 包括用于网络搜索、配额检查和引擎/时间/域过滤器的捆绑 " search.sh …
写作与研究
监控博客和RSS/Atom的种子.
写作与研究
AI-优化了使用Tavily Search API的网络搜索. 需要全面网络研究,时事搜索,域名特定搜索,或AI生成的回答摘要时使用. Tavily是LLM消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.