Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.
Add this skill
npx mdskills install sickn33/react-patternsComprehensive React reference with clear patterns, but lacks actionable agent instructions
1---2name: react-patterns3description: Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.4allowed-tools: Read, Write, Edit, Glob, Grep5---67# React Patterns89> Principles for building production-ready React applications.1011---1213## 1. Component Design Principles1415### Component Types1617| Type | Use | State |18|------|-----|-------|19| **Server** | Data fetching, static | None |20| **Client** | Interactivity | useState, effects |21| **Presentational** | UI display | Props only |22| **Container** | Logic/state | Heavy state |2324### Design Rules2526- One responsibility per component27- Props down, events up28- Composition over inheritance29- Prefer small, focused components3031---3233## 2. Hook Patterns3435### When to Extract Hooks3637| Pattern | Extract When |38|---------|-------------|39| **useLocalStorage** | Same storage logic needed |40| **useDebounce** | Multiple debounced values |41| **useFetch** | Repeated fetch patterns |42| **useForm** | Complex form state |4344### Hook Rules4546- Hooks at top level only47- Same order every render48- Custom hooks start with "use"49- Clean up effects on unmount5051---5253## 3. State Management Selection5455| Complexity | Solution |56|------------|----------|57| Simple | useState, useReducer |58| Shared local | Context |59| Server state | React Query, SWR |60| Complex global | Zustand, Redux Toolkit |6162### State Placement6364| Scope | Where |65|-------|-------|66| Single component | useState |67| Parent-child | Lift state up |68| Subtree | Context |69| App-wide | Global store |7071---7273## 4. React 19 Patterns7475### New Hooks7677| Hook | Purpose |78|------|---------|79| **useActionState** | Form submission state |80| **useOptimistic** | Optimistic UI updates |81| **use** | Read resources in render |8283### Compiler Benefits8485- Automatic memoization86- Less manual useMemo/useCallback87- Focus on pure components8889---9091## 5. Composition Patterns9293### Compound Components9495- Parent provides context96- Children consume context97- Flexible slot-based composition98- Example: Tabs, Accordion, Dropdown99100### Render Props vs Hooks101102| Use Case | Prefer |103|----------|--------|104| Reusable logic | Custom hook |105| Render flexibility | Render props |106| Cross-cutting | Higher-order component |107108---109110## 6. Performance Principles111112### When to Optimize113114| Signal | Action |115|--------|--------|116| Slow renders | Profile first |117| Large lists | Virtualize |118| Expensive calc | useMemo |119| Stable callbacks | useCallback |120121### Optimization Order1221231. Check if actually slow1242. Profile with DevTools1253. Identify bottleneck1264. Apply targeted fix127128---129130## 7. Error Handling131132### Error Boundary Usage133134| Scope | Placement |135|-------|-----------|136| App-wide | Root level |137| Feature | Route/feature level |138| Component | Around risky component |139140### Error Recovery141142- Show fallback UI143- Log error144- Offer retry option145- Preserve user data146147---148149## 8. TypeScript Patterns150151### Props Typing152153| Pattern | Use |154|---------|-----|155| Interface | Component props |156| Type | Unions, complex |157| Generic | Reusable components |158159### Common Types160161| Need | Type |162|------|------|163| Children | ReactNode |164| Event handler | MouseEventHandler |165| Ref | RefObject<Element> |166167---168169## 9. Testing Principles170171| Level | Focus |172|-------|-------|173| Unit | Pure functions, hooks |174| Integration | Component behavior |175| E2E | User flows |176177### Test Priorities178179- User-visible behavior180- Edge cases181- Error states182- Accessibility183184---185186## 10. Anti-Patterns187188| ❌ Don't | ✅ Do |189|----------|-------|190| Prop drilling deep | Use context |191| Giant components | Split smaller |192| useEffect for everything | Server components |193| Premature optimization | Profile first |194| Index as key | Stable unique ID |195196---197198> **Remember:** React is about composition. Build small, combine thoughtfully.199
Full transparency — inspect the skill content before installing.