1---2name: react-patterns3description: "Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices."4version: 1.0.05author:6 name: "sickn33 / Antigravity Community"7 github: sickn338tags: [react, patterns, frontend]9category: frontend10platforms: [macos, linux, windows]11license: MIT12metadata:13 hermes:14 source: https://skillmd.com/skills/nous-hermeshub/react-patterns15 upstream: "antigravity-awesome-skills"16 risk: "safe"17 date_added: "2026-02-27"18 original_author: "Antigravity Community"19---2021# React Patterns2223> Principles for building production-ready React applications.2425---2627## 1. Component Design Principles2829### Component Types3031| Type | Use | State |32|------|-----|-------|33| **Server** | Data fetching, static | None |34| **Client** | Interactivity | useState, effects |35| **Presentational** | UI display | Props only |36| **Container** | Logic/state | Heavy state |3738### Design Rules3940- One responsibility per component41- Props down, events up42- Composition over inheritance43- Prefer small, focused components4445---4647## 2. Hook Patterns4849### When to Extract Hooks5051| Pattern | Extract When |52|---------|-------------|53| **useLocalStorage** | Same storage logic needed |54| **useDebounce** | Multiple debounced values |55| **useFetch** | Repeated fetch patterns |56| **useForm** | Complex form state |5758### Hook Rules5960- Hooks at top level only61- Same order every render62- Custom hooks start with "use"63- Clean up effects on unmount6465---6667## 3. State Management Selection6869| Complexity | Solution |70|------------|----------|71| Simple | useState, useReducer |72| Shared local | Context |73| Server state | React Query, SWR |74| Complex global | Zustand, Redux Toolkit |7576### State Placement7778| Scope | Where |79|-------|-------|80| Single component | useState |81| Parent-child | Lift state up |82| Subtree | Context |83| App-wide | Global store |8485---8687## 4. React 19 Patterns8889### New Hooks9091| Hook | Purpose |92|------|---------|93| **useActionState** | Form submission state |94| **useOptimistic** | Optimistic UI updates |95| **use** | Read resources in render |9697### Compiler Benefits9899- Automatic memoization100- Less manual useMemo/useCallback101- Focus on pure components102103---104105## 5. Composition Patterns106107### Compound Components108109- Parent provides context110- Children consume context111- Flexible slot-based composition112- Example: Tabs, Accordion, Dropdown113114### Render Props vs Hooks115116| Use Case | Prefer |117|----------|--------|118| Reusable logic | Custom hook |119| Render flexibility | Render props |120| Cross-cutting | Higher-order component |121122---123124## 6. Performance Principles125126### When to Optimize127128| Signal | Action |129|--------|--------|130| Slow renders | Profile first |131| Large lists | Virtualize |132| Expensive calc | useMemo |133| Stable callbacks | useCallback |134135### Optimization Order1361371. Check if actually slow1382. Profile with DevTools1393. Identify bottleneck1404. Apply targeted fix141142---143144## 7. Error Handling145146### Error Boundary Usage147148| Scope | Placement |149|-------|-----------|150| App-wide | Root level |151| Feature | Route/feature level |152| Component | Around risky component |153154### Error Recovery155156- Show fallback UI157- Log error158- Offer retry option159- Preserve user data160161---162163## 8. TypeScript Patterns164165### Props Typing166167| Pattern | Use |168|---------|-----|169| Interface | Component props |170| Type | Unions, complex |171| Generic | Reusable components |172173### Common Types174175| Need | Type |176|------|------|177| Children | ReactNode |178| Event handler | MouseEventHandler |179| Ref | RefObject<Element> |180181---182183## 9. Testing Principles184185| Level | Focus |186|-------|-------|187| Unit | Pure functions, hooks |188| Integration | Component behavior |189| E2E | User flows |190191### Test Priorities192193- User-visible behavior194- Edge cases195- Error states196- Accessibility197198---199200## 10. Anti-Patterns201202| ❌ Don't | ✅ Do |203|----------|-------|204| Prop drilling deep | Use context |205| Giant components | Split smaller |206| useEffect for everything | Server components |207| Premature optimization | Profile first |208| Index as key | Stable unique ID |209210---211212## 11. File Structure213214<img width="1150" height="1438" alt="image" src="https://github.com/user-attachments/assets/10369698-472c-4695-a494-2c0672103aa1" />215216Use this image as a reference for a better file structure of the project217218---219220> **Remember:** React is about composition. Build small, combine thoughtfully.221222## When to Use223This skill is applicable to execute the workflow or actions described in the overview.224225## Limitations226- Use this skill only when the task clearly matches the scope described above.227- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.228- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.