agentleFS
komlukkomluk/scaffolding/skills/react-patterns/SKILL.md

react-patterns

Skill16 starsChanged 4 days agoMITView on GitHub

React + TypeScript component and hook standards. TRIGGER when: creating components, custom hooks, or reviewing React code. SKIP: visual styling and theme tokens (use mui-styling); global store design (use state-management).

38 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use typescript-patterns, typescript-strict and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • cohen-lielSkill

    typescript-patterns

    TypeScript best practices and patterns. Use when writing TypeScript code, defining types, working with generics, or converting JavaScript to TypeScript.

    Also in 3 projects that use this

  • MicrosoftSkill

    typescript-strict

    Enable TypeScript strict mode (strict, noImplicitAny, strictNullChecks, etc.) in a project and fix the resulting errors without weakening types, tests, or runtime behavior. Use when asked to "enable strict mode", "turn on TypeScript strict", "fix strict errors", or migrate a codebase to strict type checking.

    Also in 3 projects that use this

  • xfstudioSkill

    docker-expert

    Docker containerization expert with deep knowledge of multi-stage builds, image optimization, container security, Docker Compose orchestration, and production deployment patterns. Use PROACTIVELY for Dockerfile optimization, container issues, image size problems, security hardening, networking, and orchestration challenges.

    Also in 3 projects that use this

  • LangChainSkill

    docker-patterns

    Best practices for Docker containerization and multi-stage builds

    Also in 4 projects that use this

  • LangChainSkill

    database-migrations

    Database migration patterns and schema versioning

    Also in 4 projects that use this

  • HABUBUSSSkill

    backend-patterns

    Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.

    Also in 5 projects that use this

The file

Files
SKILL.md

React Patterns Skill

React + TypeScript standards and best practices.

When to Apply

  • Creating new React components
  • Implementing custom hooks
  • State management decisions
  • Performance optimization
  • Code review for React code

Component Standards

Component Structure Rules

RuleDescription
Functional onlyUse function components, no class components
TypeScript propsDefine Props interface for all components
Single responsibilityOne component = one purpose
Max 200 linesSplit larger components into sub-components

Component Organization

SectionOrder
1. ImportsTypes first, then libraries, then local
2. Props interfaceDefine before component
3. HooksAll hooks at top of function
4. HandlersEvent handlers after hooks
5. EffectsuseEffect after handlers
6. ReturnJSX at the end

Hook Standards

Built-in Hooks Usage

HookUse WhenAvoid When
useStateLocal component stateShared state (use Zustand)
useEffectSide effects, subscriptionsDerived state (use useMemo)
useMemoExpensive calculationsSimple values
useCallbackCallbacks passed to childrenInline handlers
useRefDOM refs, mutable valuesState that triggers renders

Custom Hook Guidelines

GuidelineDescription
Prefix with useuseFeatureName, useDataFetching
Return object{ data, loading, error }
Single responsibilityOne hook = one purpose
ReusableExtract when logic repeats 2+ times

TypeScript Requirements

Type Import Rules

RuleExample
Use import typeimport type { Props } from './types'
Use export typeexport type { ButtonProps }
Centralize typesAll types in types/index.ts
No anyUse unknown or proper types

Props Typing Standards

StandardDescription
Interface for propsinterface Props { ... }
Optional with ?title?: string
Children explicitchildren: React.ReactNode
Events typedonClick: (e: React.MouseEvent) => void

Performance Standards

Memoization Guidelines

TechniqueWhen to Use
useMemoExpensive calculations, derived data
useCallbackFunctions passed as props to memoized children
React.memoComponents with same props render same output

Re-render Prevention

CauseSolution
New object in propsMemoize with useMemo
New function in propsMemoize with useCallback
Context changesSplit contexts by update frequency
Parent re-rendersUse React.memo on child

Effect Guidelines

useEffect Rules

RuleDescription
Cleanup requiredReturn cleanup function for subscriptions
Dependency arrayInclude all referenced values
Avoid objects in depsUse primitive values or useMemo
No async directlyDefine async function inside effect

Common Effect Patterns

PatternUse Case
Data fetchingFetch on mount or dependency change
SubscriptionEvent listeners, WebSocket
DOM measurementRead layout after render
Sync externalSync state with external system

Event Handling Standards

Event Handler Naming

PatternExample
Action verbhandleClick, handleSubmit
Specific actionhandleDeleteItem, handleToggleMenu
Props callbackonAction, onChange

Event Types

EventType
ClickReact.MouseEvent<HTMLButtonElement>
ChangeReact.ChangeEvent<HTMLInputElement>
SubmitReact.FormEvent<HTMLFormElement>
KeyboardReact.KeyboardEvent

File Organization

Directory Structure

src/
├── components/
│   ├── common/          # Shared/reusable components
│   ├── [feature]/       # Feature-specific components
│   └── layout/          # Layout components
├── hooks/
│   └── use[Name].ts     # Custom hooks
├── pages/
│   └── [Page].tsx       # Route pages
├── services/
│   └── [name]Service.ts # API services
├── stores/
│   └── [name]Store.ts   # Zustand stores
└── types/
    └── index.ts         # All type definitions

Anti-Patterns to Avoid

Anti-PatternProblemSolution
useEffect for derived stateExtra rendersUse useMemo
Missing dependenciesStale closures, bugsAdd all deps
Index as keyBugs on reorderUse unique id
Prop drilling > 2 levelsHard to maintainUse Context/Zustand
Inline object propsNew reference each renderMemoize or extract
State for constantsUnnecessary complexityDefine outside component

Code Review Checklist

Component Review

  • Single responsibility principle followed
  • Props interface defined with TypeScript
  • No prop drilling beyond 2 levels
  • Hooks at top level only
  • Cleanup in useEffect where needed

Performance Review

  • Expensive calculations memoized
  • Callbacks memoized when passed to children
  • No new objects/arrays created in render
  • Keys are unique and stable

TypeScript Review

  • import type used for type imports
  • No any types
  • Props properly typed
  • Event handlers typed

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.