Token导航 LogoToken导航

Agent Skill · 开发规范

react-best-practices(React 最佳实践)

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

react-best-practices 是开发规范类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在开发规范类的 1,265 个 Skill 里排第 614。

总安装 727周安装 30GitHub Stars 1下载 238核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:react-best-practices(React 最佳实践)
来源仓库:https://github.com/pixel-process-ug/superkit-agents
仓库路径:skills/react-best-practices
安装命令:
npx skills add https://github.com/pixel-process-ug/superkit-agents --skill react-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/pixel-process-ug/superkit-agents --skill react-best-practices

这个 Skill 是做什么的

开发规范类 Skill 用来统一代码风格、目录结构和评审口径,产出多为检查清单或改写建议。

react-best-practices 用于辅助前端页面、组件、样式和交互逻辑的开发与维护,适合生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码。适用于前端开发中的最佳实践指导,可整理组件结构或定位布局和性能问题。使用时需结合项目现有设计系统、路由和构建方式,避免生成孤立片段。

涉及页面改动时应配合本地预览和构建检查确认视觉效果。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/react-best-practices

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/pixel-process-ug/superkit-agents --skill react…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

react-best-practices 怎么安装?

在终端执行 npx skills add https://github.com/pixel-process-ug/superkit-agents --skill react-best-prac…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

react-best-practices 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

react-best-practices 需要什么权限?

权限级别是操作浏览器。该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

react-best-practices 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

react-best-practices 用的人多吗?

公开数据是累计安装 727 次,近一周安装 30 次,下载 238 次,GitHub 1 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

react-best-practices 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发规范类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发规范类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
vercel-react-best-practices

Vercel React 最佳实践 · Codex、Claude

8,490,72025,918操作浏览器MIT通过
web-design-guidelines

网页设计指南 · Codex、Claude

6,686,01625,885需要联网MIT有提醒
remotion-best-practices

Remotion 最佳实践 · Codex、Claude

6,505,6323,027操作浏览器MIT有提醒
supabase-postgres-best-practices

Supabase Postgres 最佳实践 · Codex、Claude

3,175,5232,030需要联网MIT通过
next-best-practices

Next.js 最佳实践 · Codex、Claude

1,848,240841操作浏览器MIT通过
react-best-practices

React 最佳实践 · 本页

7271操作浏览器未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

React Best Practices

Overview

Apply modern React patterns to build maintainable, performant, and testable applications. This skill covers React 18/19 features including Server Components, hooks best practices, component composition, error boundaries, Suspense, context optimization, and rendering performance. It complements the senior-frontend skill with React-specific depth.

Announce at start: "I'm using the react-best-practices skill for React-specific patterns."


Phase 1: Analyze Component Requirements

Goal: Understand the component's responsibility and data requirements before coding.

Actions

  1. Identify the component's single responsibility
  2. Determine data requirements (server vs client data)
  3. Choose Server Component (default) or Client Component
  4. Identify state management needs
  5. Plan error and loading states

Server vs Client Decision Table

NeedComponent TypeReason
Direct data fetching (DB, API)Server (default)No client JS, faster
Event handlers (onClick, onChange)Client ('use client')Needs browser interactivity
useState / useReducerClientState requires client runtime
useEffect / useLayoutEffectClientSide effects require client
Browser APIs (window, localStorage)ClientServer has no browser
Third-party libs using client featuresClientLibrary requires client
No interactivity neededServer (default)Smaller bundle, faster

STOP — Do NOT proceed to Phase 2 until:

  • Component responsibility is defined (single purpose)
  • Server vs Client decision is made with rationale
  • Data requirements are mapped

Phase 2: Implement with Appropriate Patterns

Goal: Apply the correct React patterns for the component's needs.

Actions

  1. Apply appropriate composition pattern
  2. Implement hooks correctly
  3. Add error boundaries and Suspense
  4. Optimize rendering where profiling shows need
  5. Write tests that verify behavior

STOP — Do NOT proceed to Phase 3 until:

  • Patterns match the component's actual needs
  • No unnecessary complexity (no premature optimization)
  • Tests cover user-visible behavior

Phase 3: Test and Verify

Goal: Verify component behavior through tests.

Actions

  1. Write tests using accessible queries
  2. Test user interactions and outcomes
  3. Test error and loading states
  4. Verify accessibility

Query Priority (React Testing Library)

PriorityQueryUse For
1stgetByRoleAny element with ARIA role
2ndgetByLabelTextForm fields
3rdgetByPlaceholderTextFields without labels
4thgetByTextNon-interactive elements
LastgetByTestIdWhen nothing else works

STOP — Testing complete when:

  • User interactions produce expected outcomes
  • Error states are tested
  • Accessibility checks pass

Hooks Best Practices

useState

// Functional updates for state based on previous state
setCount(prev => prev + 1);

// Lazy initialization for expensive initial values
const [data, setData] = useState(() => computeExpensiveInitialValue());

// Group related state
const [form, setForm] = useState({ name: '', email: '', role: 'user' });

useEffect

Dependency Array Rules
  • Include ALL values from component scope that change over time
  • Functions inside effect should be defined inside effect or wrapped in useCallback
  • Never lie about dependencies (ESLint: react-hooks/exhaustive-deps)
Cleanup Pattern
useEffect(() => {
  const controller = new AbortController();
  async function fetchData() {
    try {
      const res = await fetch(url, { signal: controller.signal });
      const data = await res.json();
      setData(data);
    } catch (e) {
      if (e.name !== 'AbortError') setError(e);
    }
  }
  fetchData();
  return () => controller.abort();
}, [url]);
When NOT to Use useEffect
Instead of useEffect for...Use This
Data fetchingReact Query, SWR, or Server Components
Transforming dataCompute during render
User eventsEvent handlers
Syncing external storesuseSyncExternalStore

Custom Hooks Rules

  • Name starts with use
  • Encapsulate reusable stateful logic
  • One hook per concern
  • Return object (not array) for > 2 values
function useDebounce<T>(value: T, delay: number): T {
  const [debouncedValue, setDebouncedValue] = useState(value);
  useEffect(() => {
    const timer = setTimeout(() => setDebouncedValue(value), delay);
    return () => clearTimeout(timer);
  }, [value, delay]);
  return debouncedValue;
}

Component Composition Patterns

Compound Components

function Tabs({ children, defaultValue }: TabsProps) {
  const [activeTab, setActiveTab] = useState(defaultValue);
  return (
    <TabsContext.Provider value={{ activeTab, setActiveTab }}>
      <div role="tablist">{children}</div>
    </TabsContext.Provider>
  );
}

Tabs.Tab = function Tab({ value, children }: TabProps) {
  const { activeTab, setActiveTab } = useTabsContext();
  return (
    <button role="tab" aria-selected={activeTab === value} onClick={() => setActiveTab(value)}>
      {children}
    </button>
  );
};

Tabs.Panel = function Panel({ value, children }: PanelProps) {
  const { activeTab } = useTabsContext();
  if (activeTab !== value) return null;
  return <div role="tabpanel">{children}</div>;
};

Composition Decision Table

PatternUse WhenExample
Compound ComponentsRelated components sharing implicit stateTabs, Accordion, Menu
Slots (Children)Complex content layoutCard with Header/Body/Footer
Render PropsChild needs parent data for flexible renderingDataFetcher with custom render
Higher-Order ComponentCross-cutting concerns (legacy)withAuth, withTheme
Custom HookReusable stateful logic without UIuseDebounce, useLocalStorage

Slots Pattern

// Prefer composition over props for complex content
// Bad
<Card title="Hello" subtitle="World" icon={<Star />} actions={<Button>Edit</Button>} />

// Good
<Card>
  <Card.Header>
    <Card.Icon><Star /></Card.Icon>
    <Card.Title>Hello</Card.Title>
  </Card.Header>
  <Card.Actions>
    <Button>Edit</Button>
  </Card.Actions>
</Card>

Error Boundaries

Placement Strategy Decision Table

LevelPurposeExample
Route levelCatch page-level crasheserror.tsx in Next.js
Feature levelIsolate feature failuresWrap each major section
Data levelWrap async data componentsAround Suspense boundaries
Never leaf levelToo granular, adds noiseDo not wrap individual buttons

Suspense

// Nested Suspense for granular loading
<Suspense fallback={<PageSkeleton />}>
  <Header />
  <Suspense fallback={<SidebarSkeleton />}>
    <Sidebar />
  </Suspense>
  <Suspense fallback={<ContentSkeleton />}>
    <MainContent />
  </Suspense>
</Suspense>

Context Optimization

Problem: Context causes unnecessary re-renders

Solution Decision Table

TechniqueUse WhenExample
Split contexts by frequencySome values update often, some rarelyThemeContext (rare) vs UIStateContext (frequent)
Memoize context valueProvider re-renders with same datauseMemo(() => ({state, dispatch}), [state])
Use selectors (Zustand/Jotai)Need fine-grained subscriptionsuseStore(state => state.user.name)
Lift state upOnly parent needs to re-renderPass data as props to memoized children

Rendering Optimization

Memoization Decision Table

TechniqueUse WhenDo NOT Use When
React.memoRenders often with same props AND re-render is expensiveProps change every render
useMemoExpensive computation OR referential equality for depsSimple calculations
useCallbackStable function ref for memoized childrenFunction not passed as prop
None (default)Always start herePremature optimization

Rule: Profile BEFORE memoizing. Premature memoization is the most common React anti-pattern.

Virtualization

For lists > 100 items:

import { useVirtualizer } from '@tanstack/react-virtual';

Server Component Rules

  • Cannot use hooks
  • Cannot use browser APIs
  • Cannot pass functions as props to Client Components
  • CAN import and render Client Components
  • CAN pass serializable data to Client Components
// Server Component — fetches data directly
async function UserProfile({ userId }: { userId: string }) {
  const user = await db.user.findUnique({ where: { id: userId } });
  return (
    <div>
      <h1>{user.name}</h1>
      <UserActions userId={userId} /> {/* Client Component child */}
    </div>
  );
}

// Client Component — handles interactivity
'use client';
function UserActions({ userId }: { userId: string }) {
  const [isFollowing, setIsFollowing] = useState(false);
  return <Button onClick={() => toggleFollow(userId)}>Follow</Button>;
}

Anti-Patterns / Common Mistakes

Anti-PatternWhy It Is WrongCorrect Approach
useEffect for data fetchingRace conditions, no cache, no dedupReact Query or Server Components
Prop drilling > 2 levelsTight coupling, maintenance painComposition, context, or Zustand
Storing derived stateState that can be computed is unnecessary stateCompute during render
useEffect to sync state from propsUnnecessary effect, stale closuresDerive during render or use key prop
Monolithic components (> 200 lines)Hard to read, test, maintainExtract sub-components
Index as key for dynamic listsIncorrect reconciliation, stale stateStable unique ID
Direct DOM manipulationBypasses React reconciliationUse refs sparingly, prefer state
Testing state values directlyImplementation detail, breaks on refactorTest user-visible outcomes
Memoizing everythingAdds complexity, often slowerProfile first, optimize second

Documentation Lookup (Context7)

Use mcp__context7__resolve-library-id then mcp__context7__query-docs for up-to-date docs. Returned docs override memorized knowledge.

  • react — for hooks, context, suspense, server components, or React 19+ changes
  • next.js — for App Router patterns, data fetching, or server actions

Integration Points

SkillRelationship
senior-frontendFrontend skill uses React patterns from this skill
testing-strategyReact testing follows the strategy pyramid
clean-codeComponent code follows clean code principles
performance-optimizationReact rendering optimization follows measurement methodology
webapp-testingE2E tests validate React component behavior
code-reviewReview checks for React anti-patterns
acceptance-testingUI acceptance criteria drive component tests

Skill Type

FLEXIBLE — Apply these patterns based on the specific React version, project structure, and team conventions. The principles are consistent, but implementation details may vary. Always profile before optimizing.

平台分布

Codex

35%
按下载量换算83

Claude

30.12%
按下载量换算72

Cursor

18.42%
按下载量换算44

Gemini CLI

9.37%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills