react
关于
This skill provides React development standards and best practices for building high-quality components. It covers functional components, hooks usage, state management, performance optimization, and accessibility compliance. Use it when developing React components, creating custom hooks, or implementing TypeScript integration for type-safe components.
技能文档
React Development Standards
Component Structure
Rules Per File Component
Exported components should be one per file when possible; internal components can have multiple if necessary (not recommended).
- Forbid export default (refactoring and tree-shaking issues)
- Use named exports only
- Don't export internal helper components
- File order: Main exported component → Additional exported components → Internal helper components
State Management Rules
State Management Hierarchy
- Local State (useState): Used only in a single component
- Props Drilling: Allow maximum 2 levels
- Context API: Use when 3+ levels of prop drilling needed
- Global State (Zustand, etc.):
- Shared across 5+ components
- Server state synchronization needed
- Complex state logic (computed, actions)
- Developer tools support needed
Hook Usage Rules
Custom Hook Extraction Criteria
- 3+ combinations of useState/useEffect
- Reused in 2+ components
- 50+ lines of logic
Minimize useEffect Usage
- useEffect only for external system synchronization
- Handle state updates in event handlers
- Calculate derived values directly or with useMemo
- Use only when truly necessary and comment why
// ❌ Bad: useEffect for state synchronization
useEffect(() => {
setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
// ✅ Good: Direct calculation
const fullName = `${firstName} ${lastName}`;
Props Rules
Rules for Adding Props to Common Components
- Review structure before adding new props (prevent indiscriminate prop additions at shared level)
- Check for single responsibility principle violations
- Consider composition pattern for 3+ optional props
- Review if can be unified with variant prop
Conditional Rendering
Basic Rules
// Simple condition: && operator
{isLoggedIn && <UserMenu />}
// Binary choice: ternary operator
{isLoggedIn ? <UserMenu /> : <LoginButton />}
// Complex condition: separate function or early return
const renderContent = () => {
if (status === 'loading') return <Loader />;
if (status === 'error') return <Error />;
return <Content />;
};
Activity Component
- Use when pre-rendering hidden parts or maintaining state is needed
- Manage with visible/hidden mode
- Utilize for frequently toggled UI like tab switching, modal contents
Memoization
Using React Compiler
- Rely on automatic memoization
- Manual memoization (React.memo, useMemo, useCallback) only for special cases
- Use as escape hatch when compiler cannot optimize
快速安装
/plugin add https://github.com/KubrickCode/ai-config-toolkit/tree/main/react在 Claude Code 中复制并粘贴此命令以安装该技能
GitHub 仓库
相关推荐技能
evaluating-llms-harness
测试该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。
langchain
元LangChain是一个用于构建LLM应用程序的框架,支持智能体、链和RAG应用开发。它提供多模型提供商支持、500+工具集成、记忆管理和向量检索等核心功能。开发者可用它快速构建聊天机器人、问答系统和自主代理,适用于从原型验证到生产部署的全流程。
go-test
元go-test Skill为Go开发者提供全面的测试指导,涵盖单元测试、性能基准测试和集成测试的最佳实践。它能帮助您正确实现表驱动测试、子测试组织、mock接口和竞态检测,同时指导测试覆盖率分析和性能基准测试。当您编写_test.go文件、设计测试用例或优化测试策略时,这个Skill能确保您遵循Go语言的标准测试惯例。
project-structure
元这个Skill为开发者提供全面的项目目录结构设计指南和最佳实践。它涵盖了多种项目类型包括monorepo、前后端框架、库和扩展的标准组织结构。帮助团队创建可扩展、易维护的代码架构,特别适用于新项目设计、遗留项目迁移和团队规范制定。
