agentleFS
bkjain655bkjain655/agent-skills/skills/react-components-patterns/SKILL.md

react-components-patterns

Skill0 starsChanged 3 months agoMITView on GitHub

React component architecture for modern apps: Server vs Client Components, composition, forwardRef, list keys, event delegation, and avoiding invalid HTML nesting. Use when building React/Next.js UI, fixing hydration errors, or structuring component folders.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 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.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer narrow props over passing entire store

    line 80

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

Server vs Client (Next.js App Router)

Use Server Component (default)Use "use client"
Static markup, SEO hero, layout shellsEvent handlers, useState, useEffect
Data fetch at build/request timeBrowser APIs, Zustand, Recharts
No JS shipped for that subtreeRadix/shadcn interactive primitives

Composition pattern — pass Server Components as children into Client wrappers:

// page.tsx (server)
<ClientShell hero={<HeroSection />} />

// client-shell.tsx
"use client";
export function ClientShell({ hero }: { hero: React.ReactNode }) {
  return <>{hero}<InteractivePanel /></>;
}

Folder conventions

components/
  ui/           → primitives (Button, Dialog) — mostly client
  layout/       → Header, Footer, SkipToMain
  {feature}/    → domain screens composed from ui/

One component per file; named export matching filename.

forwardRef for primitives

Wrap Radix/DOM elements when parents need refs:

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, ...props }, ref) => (
    <button ref={ref} className={cn("...", className)} {...props} />
  )
);
Button.displayName = "Button";

Invalid nesting — common fixes

ProblemFix
<button> inside <button>Outer → <div role="group"> + keyboard handler, or split actions
<a> inside <a>One link wraps card; inner actions use button + stopPropagation
Block inside <p>Use <div> for rich text blocks

Guard delegated clicks:

function isInteractiveChild(target: EventTarget | null) {
  return target instanceof Element && Boolean(target.closest("button, a, input, select, textarea"));
}

Lists and keys

  • Key = stable id, never array index for reorderable lists
  • Extract row component when rows have state or handlers

Props design

  • Prefer narrow props over passing entire store
  • children for layout slots; render props only when caller needs data back
  • Colocate types: interface FooProps above component

Loading and suspense

const HeavyStep = lazy(() => import("./heavy-step"));

<Suspense fallback={<Skeleton />}>
  <HeavyStep />
</Suspense>

Anti-patterns

  • "use client" on entire pages when only a CTA needs interactivity
  • Prop drilling 5+ levels — use context or client store instead
  • Deriving state in render that should be useMemo
  • Icon-only buttons without aria-label

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.