1---2name: react-patterns3description: Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.4---56# React Patterns78## Purpose910Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.1112This skill provides operational guidance for React Patterns, including tool usage patterns, workflows, and quality expectations aligned with Syncolab skill standards.1314## When to Use1516- Use when the user needs help with React Patterns.17- When integrations for this domain are available and the task matches the workflows below.1819## When NOT to Use2021- When the task is unrelated to React Patterns or covered by a more specific skill.22- When required integrations or credentials are unavailable.2324## Expected Outcome2526- Correct use of domain tools with verified results (not fabricated).27- Clear summary of actions taken, data returned, and recommended next steps.28- Errors and missing permissions reported explicitly.2930## Inputs to Gather3132- User goal, constraints, and any identifiers (URLs, IDs, project keys).33- Available tool sets and connection status.34- Relevant context from related systems before destructive writes.3536## Workflow37381. Confirm the request maps to React Patterns and required tools are available.392. Gather identifiers and scope (project, channel, repo, date range, etc.).403. Follow the domain guidance below; prefer list/search before get/update when applicable.414. Execute tool calls using schemas from the integration; never invent tool output.425. Summarize results and offer logical follow-ups.4344# React Patterns4546> Principles for building production-ready React applications.4748---4950## 1. Component Design Principles5152### Component Types5354| Type | Use | State |55|------|-----|-------|56| **Server** | Data fetching, static | None |57| **Client** | Interactivity | useState, effects |58| **Presentational** | UI display | Props only |59| **Container** | Logic/state | Heavy state |6061### Design Rules6263- One responsibility per component64- Props down, events up65- Composition over inheritance66- Prefer small, focused components6768---6970## 2. Hook Patterns7172### When to Extract Hooks7374| Pattern | Extract When |75|---------|-------------|76| **useLocalStorage** | Same storage logic needed |77| **useDebounce** | Multiple debounced values |78| **useFetch** | Repeated fetch patterns |79| **useForm** | Complex form state |8081### Hook Rules8283- Hooks at top level only84- Same order every render85- Custom hooks start with "use"86- Clean up effects on unmount8788---8990## 3. State Management Selection9192| Complexity | Solution |93|------------|----------|94| Simple | useState, useReducer |95| Shared local | Context |96| Server state | React Query, SWR |97| Complex global | Zustand, Redux Toolkit |9899### State Placement100101| Scope | Where |102|-------|-------|103| Single component | useState |104| Parent-child | Lift state up |105| Subtree | Context |106| App-wide | Global store |107108---109110## 4. React 19 Patterns111112### New Hooks113114| Hook | Purpose |115|------|---------|116| **useActionState** | Form submission state |117| **useOptimistic** | Optimistic UI updates |118| **use** | Read resources in render |119120### Compiler Benefits121122- Automatic memoization123- Less manual useMemo/useCallback124- Focus on pure components125126---127128## 5. Composition Patterns129130### Compound Components131132- Parent provides context133- Children consume context134- Flexible slot-based composition135- Example: Tabs, Accordion, Dropdown136137### Render Props vs Hooks138139| Use Case | Prefer |140|----------|--------|141| Reusable logic | Custom hook |142| Render flexibility | Render props |143| Cross-cutting | Higher-order component |144145---146147## 6. Performance Principles148149### When to Optimize150151| Signal | Action |152|--------|--------|153| Slow renders | Profile first |154| Large lists | Virtualize |155| Expensive calc | useMemo |156| Stable callbacks | useCallback |157158### Optimization Order1591601. Check if actually slow1612. Profile with DevTools1623. Identify bottleneck1634. Apply targeted fix164165---166167## 7. Error Handling168169### Error Boundary Usage170171| Scope | Placement |172|-------|-----------|173| App-wide | Root level |174| Feature | Route/feature level |175| Component | Around risky component |176177### Error Recovery178179- Show fallback UI180- Log error181- Offer retry option182- Preserve user data183184---185186## 8. TypeScript Patterns187188### Props Typing189190| Pattern | Use |191|---------|-----|192| Interface | Component props |193| Type | Unions, complex |194| Generic | Reusable components |195196### Common Types197198| Need | Type |199|------|------|200| Children | ReactNode |201| Event handler | MouseEventHandler |202| Ref | RefObject<Element> |203204---205206## 9. Testing Principles207208| Level | Focus |209|-------|-------|210| Unit | Pure functions, hooks |211| Integration | Component behavior |212| E2E | User flows |213214### Test Priorities215216- User-visible behavior217- Edge cases218- Error states219- Accessibility220221---222223## 10. Anti-Patterns224225| ❌ Don't | ✅ Do |226|----------|-------|227| Prop drilling deep | Use context |228| Giant components | Split smaller |229| useEffect for everything | Server components |230| Premature optimization | Profile first |231| Index as key | Stable unique ID |232233---234235> **Remember:** React is about composition. Build small, combine thoughtfully.236237## Tool Availability Rules238239| Access | Behavior |240|--------|----------|241| Full tool access | Execute workflows, verify outputs, report errors. |242| Read-only | Inspect and plan; provide exact commands or dispatch request for writes. |243| No integration | State limitation; do not fabricate API results. |244245### Related tool sets246247- `react`248- `typescript`249- `storybook`250251252253## Review / Decision / Execution Criteria254255- Prefer smallest safe change; confirm destructive actions with the user.256- Use evidence from tool responses; cite IDs and links when present.257- Match integration-specific conventions (JQL, RFC3339, A1 notation, etc.).258259## Output Format260261Report:2622631. What was requested and what was done.2642. Key results (tables or bullets).2653. Errors, blockers, or missing permissions.2664. Suggested next steps.267268## Quality Bar269270- Specific, actionable, and grounded in tool output.271- Concise unless the user asked for detail.272- Respect rate limits, pagination, and API semantics.273274## Safety and Boundaries275276- Do not commit secrets, tokens, or PII into skills or user-visible logs.277- Do not fabricate validation, send, or write confirmations.278- Confirm destructive operations (delete, destroy, mass update) when appropriate.279280## Escalation / Dispatch Rules281282- If the task spans multiple domains, use or suggest related skills via `relationships.skills`.283- If write access is required but unavailable, dispatch or ask the user to enable tools.284285## References286287- Legacy content migrated from `skills/old_skills.json` (`react-patterns`).288- `skills/skill.instruction.md`, `skills/meta.instructions.md`