返回顶部
b

building-components组件构建

React component building and composition best practices. Use when creating, reviewing, or refactoring React components. Covers component structure, props patterns, composition techniques, and reusability guidelines.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
316
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

building-components

构建React组件

构建可复用、可维护的React组件的最佳实践。

适用场景

在以下情况参考这些指南:

  • - 创建新的React组件时
  • 审查组件结构和API设计时
  • 重构组件以提高可复用性时
  • 实现组件组合模式时
  • 设计props接口时

核心原则

1. 单一职责

每个组件应专注于做好一件事。将大型组件拆分为更小、更专注的模块。

2. 组合优于继承

优先选择组件组合,而非复杂的继承层级。

jsx
// ✅ 推荐:组合
function Page() {
return (







);
}

// ❌ 避免:深层嵌套
function Page() {
return ;
}

3. Props设计

  • - 使用TypeScript进行props类型定义
  • 保持props接口简洁且专注
  • 优先使用多个小型props而非少数大型对象
  • 使用children prop进行内容组合

4. 组件结构

tsx // ✅ 推荐结构 import { FC } from react;

interface Props {
title: string;
children?: React.ReactNode;
}

export const Card: FC = ({ title, children }) => {
return (


{title}


{children}

);
};

5. 状态管理

  • - 将状态尽可能保持在离使用位置最近的地方
  • 仅在必要时提升状态
  • 考虑使用自定义hooks实现可复用的状态逻辑

常见模式

复合组件

适用于Select/Option、Tabs/TabList/Tab/TabPanel等灵活API。

Render Props

用于在保持渲染控制的同时共享行为。

Hooks

用于跨组件共享有状态逻辑。

相关技能

  • - vercel-react-best-practices
  • next-best-practices
  • vercel-composition-patterns

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 building-components-1776207969 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 building-components-1776207969 技能

通过命令行安装

skillhub install building-components-1776207969

下载

⬇ 下载 building-components v1.0.0(免费)

文件大小: 1.73 KB | 发布时间: 2026-4-15 13:29

v1.0.0 最新 2026-4-15 13:29
Initial release of building-components skill, providing React component best practices:

- Covers guidelines for structure, props patterns, and composition techniques.
- Emphasizes single responsibility, composition over inheritance, and clean props design.
- Includes recommended component structure with TypeScript.
- Outlines state management and common patterns (compound components, render props, hooks).

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部