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.
In this repository23 other files it gives its agents.
- client-document-exportSkill
- cloudflare-turnstile-nextjsSkill
- ga4-analytics-nextjsSkill
- git-repo-privacy-auditSkill
- hardened-contact-form-nextjsSkill
- html-semantic-markupSkill
- multi-step-wizard-flowSkill
- nextjs-api-routesSkill
- nextjs-app-routerSkill
- nextjs-seo-metadataSkill
- nextjs-ui-foundationSkill
- next-themes-dark-modeSkill
- playwright-e2e-testingSkill
- react-hooks-patternsSkill
- recharts-dashboardSkill
- resend-email-nextjsSkill
- server-pdf-playwrightSkill
- shadcn-ui-setupSkill
- specialized-form-inputsSkill
- tailwind-css-v4Skill
- vitest-unit-testingSkill
- web-accessibility-wcagSkill
- zustand-persist-stateSkill
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
- Distinctive: line 80
Prefer narrow props over passing entire store
≈ “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.
Files
React Component Patterns
Server vs Client (Next.js App Router)
| Use Server Component (default) | Use "use client" |
| Static markup, SEO hero, layout shells | Event handlers, useState, useEffect |
| Data fetch at build/request time | Browser APIs, Zustand, Recharts |
| No JS shipped for that subtree | Radix/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
| Problem | Fix |
<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
childrenfor layout slots; render props only when caller needs data back- Colocate types:
interface FooPropsabove 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
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
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.

