跳到主内容
智客 ZICQ

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

React Best Practices

反应性能优化指南出自马斯特拉工程. 这种技能应用于写作,审查或重构回放代码,以确保最佳的性能模式. 触发涉及React组件,数据获取,捆绑优化,或性能改进等任务.

2468 安装量

官方网址:skills.sh

技能介绍

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

做什么

反应性能优化指南出自马斯特拉工程. 这种技能应用于写作,审查或重构回放代码,以确保最佳的性能模式. 触发涉及React组件,数据获取,捆绑优化,或性能改进等任务.

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React Best Practices、Overview、When to Apply、Priority-Ordered Guidelines、Quick Reference、Critical Patterns (Apply First)。

文件分析

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

官方 description(原文)

React performance optimization guidelines from Mastra Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements.

React Best PracticesOverviewWhen to ApplyPriority-Ordered GuidelinesQuick ReferenceCritical Patterns (Apply First)Medium-Impact PatternsRendering PatternsJavaScript PatternsReferencesRule Categories in `references/rules/`

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
react-best-practices
description
React performance optimization guidelines from Mastra Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 2
  • references/react-best-practices-reference.md
  • references/rules/

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

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

安装这个技能

Skills CLI ↗

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

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

交给 Agent 安装

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

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

GitHub 完整包 ↗

终端安装 · Skills CLI

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

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

npx skills add 'https://github.com/mastra-ai/mastra' --skill 'react-best-practices'

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

阅读排版
--- name: react-best-practices description: React performance optimization guidelines from Mastra Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements. --- # React Best Practices ## Overview Routing and priority guide for React performance and quality, containing 26 rules across 9 categories. Rule files hold the detailed explanations, examples, review smells, and impact metrics. ## When to Apply Reference these guidelines when: - Writing new React components - Implementing data fetching - Reviewing code for performance issues - Refactoring existing React code - Optimizing bundle size or load times ## Priority-Ordered Guidelines Rules are prioritized by impact: | Priority | Category | Impact | | -------- | ------------------------- | ----------------------------- | | 1 | Eliminating Waterfalls | CRITICAL | | 2 | Bundle Size Optimization | CRITICAL | | 3 | Client-Side Data Fetching | MEDIUM-HIGH | | 4 | Re-render Optimization | MEDIUM | | 5 | Rendering Performance | MEDIUM | | 6 | JavaScript Performance | LOW-MEDIUM | | 7 | Component Structure | MEDIUM-HIGH (maintainability) | | 8 | Testing | MEDIUM-HIGH (correctness) | | 9 | Type Safety | HIGH | ## Quick Reference ### Critical Patterns (Apply First) **Eliminate Waterfalls:** - Use `Promise.all()` for independent async operations (`async-parallel`) **Reduce Bundle Size:** - Avoid barrel file imports, import directly from source (`bundle-barrel-imports`) - Defer non-critical third-party libraries (`bundle-defer-third-party`) ### Medium-Impact Patterns **Client-Side Data Fetching:** - Use Tanstack Query for automatic request deduplication (`client-request-dedupe`) - Dependent query params are the value or `undefined`, never `| null` or a fake fallback; narrow at the caller so hooks stay strict, or guard with `skipToken` when the hook must accept an optional param (`client-request-dedupe`) **Re-render Optimization:** - Use lazy state initialization for expensive values (`rerender-lazy-state-init`) - Apply `startTransition` for non-urgent updates (`rerender-transitions`) - Keep UI handlers plain; use Effect Events only for effect-fired logic (`rerender-useeffect-function-calls`) - Never reset state with `useEffect`; lift the discriminant and remount the branch (`rerender-no-useeffect-state-reset`) - Never add `useMemo` or `useCallback`; leave memoization decisions to developers with profiler evidence (`rerender-no-usememo-usecallback`) - Never call `setState` during render or inside `useEffect`; derive during render or move state ownership to an intermediate component (`rerender-no-setstate-in-render-or-effect`) **Component Structure:** - One domain component/hook per file, one responsibility each — split bloated components (`structure-single-responsibility`) - Keep component, hook, function, and utility APIs narrow: split oversized props, arguments, and return objects into focused units composed at the component level; wrapping the same values in one object is not a fix (`structure-narrow-apis`) - Use PascalCase components for JSX-returning helpers; keep lowercase helpers for non-JSX values (`structure-component-naming`) - Derive props/params instead of accepting a value computable from another arg (`structure-derive-dont-duplicate`) - Extract complex derived logic into named locals plus predicates or pure helpers with early returns: oversized conditions, nested ternaries, ternaries that compute instead of picking (multi-line branches, or an `as` cast re-asserting what the condition tested), fallback chains, and `let`-based render prep are code smells, in render prep and in hook options, request builders, config maps, and reducers alike (`structure-complex-derived-logic`) - Pick the view with early `if` guards but keep the layout wrapper in one place — branch a body component, don't ternary or duplicate the shell (`structure-early-return-render-branches`) - For a fixed set of items, write one component per item with explicit props that owns its data and loading — don't map a config-object array onto a component shape (`structure-composition-over-config`) **Testing:** - BDD tests that drive the real `@mastra/client-js` + React Query stack and mock only the network; never `vi.mock` our own hooks/services/auth gating or the SDK (`testing-bdd-no-mocks`) - Avoid class-name assertions for visual behavior; prefer computed styles, user-visible behavior, or browser validation, and prefer no test over a className-only implementation mirror (`testing-no-classname-assertions`) **Type Safety:** - No `as` type assertions anywhere — production **or tests**; narrow with real type guards, query generics (`querySelector`, `getByRole`), typed fixture factories, or `implements` on mocks. `as const` is the only allowed form. Do not replace a cast with a domain-type predicate that only checks `typeof value === 'object'`; call that an `isRecord` helper or validate the fields used (`types-no-type-assertions`) - Use `undefined` and optional `?` for absence, not `null`; convert external `null` at boundaries, and keep leaf props strict so callers own absence and fallback rendering (`types-no-null`) ### Rendering Patterns - Animate SVG wrappers, not SVG elements directly (`rendering-animate-svg-wrapper`) - Use `content-visibility: auto` for long lists (`rendering-content-visibility`) ### JavaScript Patterns - Use Set/Map for repeated lookups (`js-set-map-lookups`) - Use `toSorted()` instead of `sort()` for immutability (`js-tosorted-immutable`) - Early length check for array comparisons (`js-length-check-first`) ## References Rule files are the canonical source for detailed guidance and examples: - `references/react-best-practices-reference.md` - Rule catalog with category order and rule-file paths - `references/rules/` - Canonical individual rule files organized by category Load only the relevant rule file when implementing or reviewing a specific pattern. Use the catalog to choose the right rule without loading every example. To look up a specific pattern, grep the rules directory: ``` grep -l "Promise.all" references/rules/ grep -l "barrel" references/rules/ grep -l "Tanstack" references/rules/ ``` ## Rule Categories in `references/rules/` - `async-*` - Waterfall elimination (1 rule) - `bundle-*` - Bundle size optimization (2 rules) - `client-*` - Client-side data fetching (1 rule) - `rerender-*` - Re-render optimization (6 rules) - `rendering-*` - DOM rendering performance (2 rules) - `js-*` - JavaScript micro-optimizations (3 rules) - `types-*` - Type-safety / no-`as`-cast and no-`null` rules (2 rules) - `structure-*` - Component/hook/function/utility structure (7 rules) - `testing-*` - BDD tests + mock-only-the-network policy + no className implementation-mirror assertions (2 rules)

相关技能

写作与研究

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消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.