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

react-patterns

Skill15 starsChanged 2 months 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).

29 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use typescript-strict, fastapi-patterns and 6 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.
  • kevinaimonsterSkill

    typescript-strict

    TypeScript strict mode and advanced type system assistant. Helps write strictly-typed TypeScript code with generics, type guards, utility types, conditional types, mapped types, and template literal types. Trigger when user says 'TypeScript types' 'type gymnastics' 'TypeScript generics' 'strict TypeScript' 'type guard' 'TS类型' 'TypeScript严格模式' '类型体操' '泛型怎么写' 'TS type help'. Keywords: TypeScript, strict mode, generics, type guard, utility types, conditional types, mapped types, template literal types, infer, extends, keyof, typeof, type narrowing, discriminated unions, type assertion, type predicate, type gymnastics, TS, 类型体操, 泛型, 类型守卫, 严格类型

    Also in 3 projects that use this

  • hieutrtrSkill

    fastapi-patterns

    FastAPI framework mechanics and advanced patterns. Use when configuring middleware, creating dependency injection chains, implementing WebSocket endpoints, customizing OpenAPI documentation, setting up CORS, building authentication dependencies (JWT validation, role-based access), implementing background tasks, or managing application lifespan (startup/shutdown). Does NOT cover basic endpoint CRUD or repository/service patterns (use python-backend-expert) or testing (use pytest-patterns).

    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

  • rohitg00Skill

    django-patterns

    Django architecture patterns including DRF, ORM optimization, signals, middleware, and project structure

    Also in 3 projects that use this

  • rohitg00Skill

    springboot-patterns

    Spring Boot patterns including JPA repositories, REST controllers, layered services, and configuration

    Also in 3 projects that use this

  • Svenja-devSkill

    e2e-testing

    Also in 4 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.