agentleFS
tryonelovetryonelove/skills/composition/SKILL.md

composition

Skill0 starsChanged 3 months agoMITView on GitHub

Design, implement, and refactor React components with composition, shared layout components, and early returns for mutually exclusive UI states. Use when JSX has tangled conditional rendering, loading/error/empty/success states are hard to reason about, a component needs clearer boundaries, or TypeScript cannot narrow state cleanly because checks remain inside JSX.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. Akunda123/SVIXAGENT★ 33same name
    2. editframe/skills★ 19same name
    3. taniwhaai/arai★ 7same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use component boundaries to keep related markup, styles, and behavior cohesive.

    line 8
  2. Distinctive:

    Put state-specific checks and content only in the branch where they apply.

    line 16
  3. Distinctive:

    Keep simple optional fragments inline when they do not represent a distinct component state, such as an optional badge or assignee.

    line 56
  4. Distinctive:

    Use early returns when branches are mutually exclusive views.

    line 57
  5. Distinctive:

    Do not extract a component merely to hide conditions.

    line 61
  6. Distinctive:

    Do not replace one conditional maze with a layout component full of flags.

    line 62

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Composition

Use component boundaries to keep related markup, styles, and behavior cohesive. Prefer code whose structure makes each user-visible state obvious when read from top to bottom.

Refactoring workflow

  1. Identify the states a user can actually see, such as pending, error, empty, and success.
  2. Sketch each state as boxes. Separate the frame shared by every state from the content that changes.
  3. Extract the shared frame into a small layout component that accepts children and only the props needed by that frame.
  4. Render mutually exclusive states with ordered top-level early returns.
  5. Put state-specific checks and content only in the branch where they apply.
  6. Let the final branch represent the fully narrowed success state.
  7. Reassess the abstraction when the layout itself accumulates many conditional props.
function Layout({ children, title }: { children: ReactNode; title?: string }) {
  return (
    <Card>
      <CardHeading>{title ?? "Items"}</CardHeading>
      <CardContent>{children}</CardContent>
    </Card>
  )
}

function ItemList() {
  const { data, error, isPending } = useItems()

  if (isPending) {
    return <Layout><Skeleton /></Layout>
  }

  if (error) {
    return <Layout><ErrorMessage error={error} /></Layout>
  }

  if (!data || data.items.length === 0) {
    return <Layout><EmptyScreen /></Layout>
  }

  return (
    <Layout title={data.title}>
      {data.assignee && <UserInfo {...data.assignee} />}
      {data.items.map((item) => <Item key={item.id} {...item} />)}
    </Layout>
  )
}

Decision rules

  • Keep simple optional fragments inline when they do not represent a distinct component state, such as an optional badge or assignee.
  • Use early returns when branches are mutually exclusive views. Treat each return as one screen state.
  • Order guards from transient or exceptional states toward the normal success state.
  • Accept repeating a small layout wrapper across branches. Prefer local, readable duplication over coupled Boolean conditions.
  • Preserve self-contained components when useful; data fetching and composition can coexist.
  • Do not extract a component merely to hide conditions. Extract a meaningful shared boundary, then move state selection outside JSX.
  • Do not replace one conditional maze with a layout component full of flags. Split or redesign the abstraction when variants stop sharing a coherent frame.

Review checklist

  • Can a reader identify every user-visible state without evaluating nested JSX expressions?
  • Can two mutually exclusive branches render at the same time? If so, fix the state model or guard order.
  • Does every state render only the data-dependent UI valid for that state?
  • Does TypeScript narrow required data by the final branch without assertions or repeated optional checks?
  • Can a new state be added as one isolated branch without modifying unrelated branches?
  • Does the shared layout remain simple and cohesive?

Preserve intent

Apply this pattern when it lowers cognitive load. Do not ban conditional rendering: inline conditions remain appropriate for small optional additions within one state. Optimize for clear user-visible states, sound type narrowing, and components that can evolve without cross-branch regressions.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.