agentleFS
manish1803manish1803/nextjs-fullstack-skills/skills/01-frontend-engineering/react-component-engineering/SKILL.md

react-component-engineering

Skill2 starsChanged 4 months agoMITView on GitHub

Engineer clean, reusable, well-typed React components and hooks with correct composition, memoization, and prop API design. Use whenever the user is building, reviewing, or refactoring React components, designing a component's prop interface, splitting a large component, extracting custom hooks, or asking about React performance (re-renders, memo, useMemo/useCallback). Trigger on "build a component", "this component is doing too much", "why does this re-render", "extract a hook".

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Single responsibility: if a component both fetches data, manages complex state, AND renders deep markup, split it into a container (logic) …

    line 11
  2. Very specific:

    Prefer explicit, narrow props over a generic props: any or a giant config object.

    line 13
  3. Very specific:

    Use discriminated unions for variant props (variant: 'primary' | 'secondary') instead of multiple booleans (isPrimary, isSecondary).

    line 14
  4. Very specific:

    Default to composition (children, slots) over prop-drilling deeply nested config.

    line 16
  5. Very specific:

    Use the key prop correctly on lists (stable, unique IDs — never array index if the list can reorder/filter).

    line 24
  6. Very specific:

    Use ComponentPropsWithoutRef<'element'> extension so native attributes pass through for free.

    line 42

≈ “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

React Component Engineering Skill

Guides writing React components that are typed, composable, testable, and performant by default — not just "working."

Component design checklist

  1. Single responsibility: if a component both fetches data, manages complex state, AND renders deep markup, split it into a container (logic) + presentational component, or extract a custom hook for the logic.
  2. Prop API design:
    • Prefer explicit, narrow props over a generic props: any or a giant config object.
    • Use discriminated unions for variant props (variant: 'primary' | 'secondary') instead of multiple booleans (isPrimary, isSecondary).
    • Expose a className/asChild-style escape hatch on reusable UI components so consumers can extend styling without forking the component.
    • Default to composition (children, slots) over prop-drilling deeply nested config.
  3. State placement: lift state only as high as the nearest common consumer needs it — no higher. Prefer colocated useState over global state for anything not actually shared.
  4. Custom hooks: extract a hook (useXyz) whenever logic (data fetching, subscriptions, derived state, event listeners) is reused across ≥2 components or when it makes the component's JSX easier to read at a glance.

Performance rules (apply only when there's a measured or obvious problem — don't over-optimize by default)

  • React.memo a component only if it re-renders often with the same props and the render itself is expensive.
  • useMemo/useCallback are for referential stability passed to memoized children or expensive computations — not a blanket habit on every value.
  • Move state down / split components to shrink re-render blast radius before reaching for memoization.
  • Use the key prop correctly on lists (stable, unique IDs — never array index if the list can reorder/filter).

TypeScript conventions

type ButtonProps = {
  variant?: 'primary' | 'secondary' | 'ghost';
  size?: 'sm' | 'md' | 'lg';
  isLoading?: boolean;
} & React.ComponentPropsWithoutRef<'button'>;

export function Button({ variant = 'primary', size = 'md', isLoading, className, children, ...rest }: ButtonProps) {
  return (
    <button className={cn(buttonVariants({ variant, size }), className)} disabled={isLoading || rest.disabled} {...rest}>
      {isLoading ? <Spinner /> : children}
    </button>
  );
}

Use ComponentPropsWithoutRef<'element'> extension so native attributes pass through for free.

Anti-patterns to flag

  • Components over ~200 lines mixing data fetching, business logic, and deep JSX
  • Passing entire objects as props when only 2 fields are used (breaks memoization, obscures the real dependency)
  • useEffect used to derive state from other state (compute it inline during render instead)
  • Prop names that leak implementation detail (isApiLoading) instead of user-facing intent (isLoading)
  • Inline anonymous functions/objects passed to memoized children without useCallback/useMemo when it actually defeats the memoization

Example prompt this skill should trigger on

"This ProductCard component is 300 lines and handles fetching, cart logic, and rendering — help me clean it up."

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.