All skills
vercel-labs avatar

/composition-patterns

@a5343bd official
by Vercel Labsvercel-labs/agent-skills32k stars
2,784

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

Use this Skill: https://skilld.dev/gh/vercel-labs/agent-skills/composition-patterns

This session only. Nothing lands on disk.

rulespatterns-children-over-render-props.md

≈472 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Prefer Children Over Render Props

Use children for composition instead of renderX props. Children are more readable, compose naturally, and don't require understanding callback signatures.

Incorrect (render props):

function Composer({
  renderHeader,
  renderFooter,
  renderActions,
}: {
  renderHeader?: () => React.ReactNode
  renderFooter?: () => React.ReactNode
  renderActions?: () => React.ReactNode
}) {
  return (
    <form>
      {renderHeader?.()}
      <Input />
      {renderFooter ? renderFooter() : <DefaultFooter />}
      {renderActions?.()}
    </form>
  )
}

// Usage is awkward and inflexible
return (
  <Composer
    renderHeader={() => <CustomHeader />}
    renderFooter={() => (
      <>
        <Formatting />
        <Emojis />
      </>
    )}
    renderActions={() => <SubmitButton />}
  />
)

Correct (compound components with children):

function ComposerFrame({ children }: { children: React.ReactNode }) {
  return <form>{children}</form>
}

function ComposerFooter({ children }: { children: React.ReactNode }) {
  return <footer className='flex'>{children}</footer>
}

// Usage is flexible
return (
  <Composer.Frame>
    <CustomHeader />
    <Composer.Input />
    <Composer.Footer>
      <Composer.Formatting />
      <Composer.Emojis />
      <SubmitButton />
    </Composer.Footer>
  </Composer.Frame>
)

When render props are appropriate:

// Render props work well when you need to pass data back
<List
  data={items}
  renderItem={({ item, index }) => <Item item={item} index={index} />}
/>

Use render props when the parent needs to provide data or state to the child. Use children when composing static structure.

Source: SKILL.md on GitHub

No alerts27d3 checks · Risk SAFE
  • Gen Agent Trust Hub27d

    This skill provides React composition patterns and architectural guidelines for frontend development. No security considerations were identified as the skill consists entirely of instructional documentation.

  • Socket27d

    No alerts

  • Snyk27d

    Risk: LOW · No issues

Signed by skilld at a5343bd. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago
metadata
{
  "author": "vercel",
  "version": "1.0.0"
}
  • React
  • Refactoring
  • composition
  • component-architecture
  • state-management
  • compound-components
  • react19
  • component-library

README badge

README badge for vercel-labs/agent-skills/composition-patterns

Teaches React composition patterns to avoid boolean prop proliferation and build flexible component libraries using compound components, context providers, and state lifting. Includes guidelines for refactoring component architecture and references React 19 API changes like removing forwardRef in favor of use().

Generated from the current SKILL.md.

Does this skill cover React 19 changes?
Yes. The skill includes a React 19 APIs section covering changes like removing forwardRef in favor of use() and useContext() updates, but those rules only apply if you're using React 19 or later.
What specific composition patterns does this skill teach?
The skill covers compound components, render props, context providers, state lifting, and explicit variants. It prioritizes avoiding boolean prop proliferation by composing components instead.
Is this skill for building my own components or refactoring existing ones?
Both. Use it when refactoring components with too many boolean props, designing new component libraries, or reviewing component architecture decisions.
Does this skill include code examples?
Yes. Individual rule files contain incorrect and correct code examples with explanations for each pattern.

Generated from the current SKILL.md. These answers refresh after source changes.