← 返回 Skills 市场
wpank

React Composition

作者 wpank · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
843
总下载
0
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install react-composition
功能描述
React composition patterns for scalable component architecture. Use when refactoring components with boolean prop proliferation, building flexible component libraries, designing reusable component APIs, or working with compound components and context providers.
使用说明 (SKILL.md)

React Composition Patterns

Composition patterns for building flexible, maintainable React components. Avoid boolean prop proliferation by using compound components, lifting state, and composing internals. These patterns make codebases easier to work with as they scale.

When to Apply

  • Refactoring components with many boolean props
  • Building reusable component libraries
  • Designing flexible component APIs
  • Working with compound components or context providers

Pattern Overview

# Pattern Impact
1 Avoid Boolean Props CRITICAL
2 Compound Components HIGH
3 Context Interface (DI) HIGH
4 State Lifting HIGH
5 Explicit Variants MEDIUM
6 Children Over Render Props MEDIUM

Installation

OpenClaw / Moltbot / Clawbot

npx clawhub@latest install react-composition

1. Avoid Boolean Prop Proliferation

Don't add boolean props like isThread, isEditing, isDMThread to customize behavior. Each boolean doubles possible states and creates unmaintainable conditional logic. Use composition instead.

// BAD — boolean props create exponential complexity
function Composer({ isThread, isDMThread, isEditing, isForwarding }: Props) {
  return (
    \x3Cform>
      \x3CInput />
      {isDMThread ? \x3CAlsoSendToDMField /> : isThread ? \x3CAlsoSendToChannelField /> : null}
      {isEditing ? \x3CEditActions /> : isForwarding ? \x3CForwardActions /> : \x3CDefaultActions />}
    \x3C/form>
  )
}

// GOOD — composition eliminates conditionals
function ChannelComposer() {
  return (
    \x3CComposer.Frame>
      \x3CComposer.Input />
      \x3CComposer.Footer>\x3CComposer.Attachments />\x3CComposer.Submit />\x3C/Composer.Footer>
    \x3C/Composer.Frame>
  )
}

function ThreadComposer({ channelId }: { channelId: string }) {
  return (
    \x3CComposer.Frame>
      \x3CComposer.Input />
      \x3CAlsoSendToChannelField id={channelId} />
      \x3CComposer.Footer>\x3CComposer.Submit />\x3C/Composer.Footer>
    \x3C/Composer.Frame>
  )
}

Each variant is explicit about what it renders. Shared internals without a monolithic parent.

2. Compound Components

Structure complex components with shared context. Each subcomponent accesses state via context, not props. Export as a namespace object.

const ComposerContext = createContext\x3CComposerContextValue | null>(null)

function ComposerProvider({ children, state, actions, meta }: ProviderProps) {
  return \x3CComposerContext value={{ state, actions, meta }}>{children}\x3C/ComposerContext>
}
function ComposerInput() {
  const { state, actions: { update }, meta: { inputRef } } = use(ComposerContext)
  return \x3CTextInput ref={inputRef} value={state.input}
    onChangeText={(t) => update((s) => ({ ...s, input: t }))} />
}

const Composer = {
  Provider: ComposerProvider, Frame: ComposerFrame,
  Input: ComposerInput, Submit: ComposerSubmit, Footer: ComposerFooter,
}

// Consumers compose exactly what they need
\x3CComposer.Provider state={state} actions={actions} meta={meta}>
  \x3CComposer.Frame>
    \x3CComposer.Input />
    \x3CComposer.Footer>\x3CComposer.Formatting />\x3CComposer.Submit />\x3C/Composer.Footer>
  \x3C/Composer.Frame>
\x3C/Composer.Provider>

3. Generic Context Interface (Dependency Injection)

Define a generic interface with state, actions, and meta. Any provider implements this contract — enabling the same UI to work with different state implementations. The provider is the only place that knows how state is managed.

interface ComposerContextValue {
  state: { input: string; attachments: Attachment[]; isSubmitting: boolean }
  actions: { update: (fn: (s: ComposerState) => ComposerState) => void; submit: () => void }
  meta: { inputRef: React.RefObject\x3CTextInput> }
}

// Provider A: Local state for ephemeral forms
function ForwardMessageProvider({ children }: { children: React.ReactNode }) {
  const [state, setState] = useState(initialState)
  return (
    \x3CComposerContext value={{ state, actions: { update: setState, submit: useForwardMessage() },
      meta: { inputRef: useRef(null) } }}>{children}\x3C/ComposerContext>
  )
}

// Provider B: Global synced state for channels
function ChannelProvider({ channelId, children }: Props) {
  const { state, update, submit } = useGlobalChannel(channelId)
  return (
    \x3CComposerContext value={{ state, actions: { update, submit },
      meta: { inputRef: useRef(null) } }}>{children}\x3C/ComposerContext>
  )
}

Swap the provider, keep the UI. Same Composer.Input works with both.

4. Lift State into Providers

Move state into dedicated provider components so sibling components outside the main UI can access and modify state without prop drilling or refs.

// BAD — state trapped inside component; siblings can't access it
function ForwardMessageComposer() {
  const [state, setState] = useState(initialState)
  return \x3CComposer.Frame>\x3CComposer.Input />\x3CComposer.Footer />\x3C/Composer.Frame>
}
function ForwardMessageDialog() {
  return (
    \x3CDialog>
      \x3CForwardMessageComposer />
      \x3CMessagePreview />        {/* Can't access composer state */}
      \x3CForwardButton />         {/* Can't call submit */}
    \x3C/Dialog>
  )
}

// GOOD — state lifted to provider; any descendant can access it
function ForwardMessageProvider({ children }: { children: React.ReactNode }) {
  const [state, setState] = useState(initialState)
  const submit = useForwardMessage()
  return (
    \x3CComposer.Provider state={state} actions={{ update: setState, submit }}
      meta={{ inputRef: useRef(null) }}>{children}\x3C/Composer.Provider>
  )
}
function ForwardMessageDialog() {
  return (
    \x3CForwardMessageProvider>
      \x3CDialog>
        \x3CForwardMessageComposer />
        \x3CMessagePreview />       {/* Reads state from context */}
        \x3CForwardButton />        {/* Calls submit from context */}
      \x3C/Dialog>
    \x3C/ForwardMessageProvider>
  )
}
function ForwardButton() {
  const { actions } = use(Composer.Context)
  return \x3CButton onPress={actions.submit}>Forward\x3C/Button>
}

Key insight: Components that need shared state don't have to be visually nested — they just need to be within the same provider.

5. Explicit Variant Components

Instead of one component with many boolean props, create explicit variants. Each composes the pieces it needs — self-documenting, no impossible states.

// BAD — what does this render?
\x3CComposer isThread isEditing={false} channelId="abc" showAttachments showFormatting={false} />

// GOOD — immediately clear
\x3CThreadComposer channelId="abc" />
\x3CEditMessageComposer messageId="xyz" />
\x3CForwardMessageComposer messageId="123" />

Each variant is explicit about its provider/state, UI elements, and actions.

6. Children Over Render Props

Use children for composition instead of renderX props. Children are more readable and compose naturally.

// BAD — render props
\x3CComposer
  renderHeader={() => \x3CCustomHeader />}
  renderFooter={() => \x3C>\x3CFormatting />\x3CEmojis />\x3C/>}
/>

// GOOD — children composition
\x3CComposer.Frame>
  \x3CCustomHeader />
  \x3CComposer.Input />
  \x3CComposer.Footer>\x3CComposer.Formatting />\x3CSubmitButton />\x3C/Composer.Footer>
\x3C/Composer.Frame>

When render props are appropriate: When the parent needs to pass data back (e.g., renderItem={({ item, index }) => ...}).

Decision Guide

  1. Component has 3+ boolean props? → Extract explicit variants (1, 5)
  2. Component has render props? → Convert to compound components (2, 6)
  3. Siblings need shared state? → Lift state to provider (4)
  4. Same UI, different data sources? → Generic context interface (3)
  5. Building a component library? → Apply all patterns together
安全使用建议
This skill is documentation-only and appears coherent for teaching React composition patterns. Before installing or running any suggested npx commands, verify the author and source (the registry owner is an opaque ID and homepage is missing). If you plan to run the npx install commands, inspect the repository or package contents first — npx can execute remote code. Prefer cloning or reviewing the skill files locally rather than blindly running network-installer commands, and check license and attribution if you will include examples in your codebase.
功能分析
Type: OpenClaw Skill Name: react-composition Version: 1.0.0 The skill bundle provides educational content and code examples for React composition patterns. All `tsx` code snippets are illustrative, and the `SKILL.md` and `README.md` files contain no prompt injection attempts or instructions for the AI agent to perform malicious actions. Installation commands like `npx clawhub install` and `npx add` are standard methods for users to install skills or packages, and local `cp -r` commands are for manual installation, none of which indicate malicious intent within the skill itself. There is no evidence of data exfiltration, persistence, or unauthorized execution.
能力评估
Purpose & Capability
The name and description (React composition patterns) match the SKILL.md and README content: both contain design guidance and example code for compound components, context providers, and state-lifting. No unrelated capabilities or credentials are requested.
Instruction Scope
The runtime instructions are purely documentation and examples showing patterns and sample code; they do not instruct the agent to read local files, environment variables, or transmit data to external endpoints. There is no scope creep in the SKILL.md content.
Install Mechanism
There is no formal install spec included (instruction-only), which is low risk. The README suggests using npx (e.g., `npx clawhub@latest install react-composition` and an `npx add https://github.com/...` line). Those commands would execute code fetched from the network if run — treat them as external-install actions and verify the source before running. The README's `npx add` URL points to a GitHub tree (not a standard package URL), which is unusual and worth manual verification.
Credentials
The skill declares no required environment variables, no credentials, and no config paths. The SKILL.md does not reference hidden env vars or secrets. Requested privileges are proportional to the skill's purpose (none).
Persistence & Privilege
The skill is not configured to be always-enabled and does not request persistent system presence. It's user-invocable only and contains no install-time scripts or mechanisms that would modify other skills or system-wide settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install react-composition
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /react-composition 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release covering key React composition patterns for scalable, maintainable component design: - Documents strategies to avoid boolean prop proliferation using composition. - Explains compound components and use of context for state sharing. - Introduces a generic provider interface for decoupled state management. - Recommends lifting state into providers for easier state sharing. - Advocates for explicit variant components over monolithic prop-driven ones. - Describes using children for flexible composition instead of render props. - Provides practical decision guides and clear code examples for each pattern.
元数据
Slug react-composition
版本 1.0.0
许可证
累计安装 2
当前安装数 2
历史版本数 1
常见问题

React Composition 是什么?

React composition patterns for scalable component architecture. Use when refactoring components with boolean prop proliferation, building flexible component libraries, designing reusable component APIs, or working with compound components and context providers. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 843 次。

如何安装 React Composition?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install react-composition」即可一键安装,无需额外配置。

React Composition 是免费的吗?

是的,React Composition 完全免费(开源免费),可自由下载、安装和使用。

React Composition 支持哪些平台?

React Composition 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 React Composition?

由 wpank(@wpank)开发并维护,当前版本 v1.0.0。

💬 留言讨论