component-patterns
React/Next.js component design pattern library. Provides Compound/Render Props/HOC/Custom Hooks patterns, state management strategies (Zustand/React Query/Context), and folder structure conventions as a frontend-dev extension skill. Use for requests like 'component patterns', 'React patterns', 'state management', 'folder structure', 'Custom Hook', 'component separation', and other frontend architecture design tasks. However, actual code implementation or backend logic is outside this skill's scope.
Best use case
component-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
React/Next.js component design pattern library. Provides Compound/Render Props/HOC/Custom Hooks patterns, state management strategies (Zustand/React Query/Context), and folder structure conventions as a frontend-dev extension skill. Use for requests like 'component patterns', 'React patterns', 'state management', 'folder structure', 'Custom Hook', 'component separation', and other frontend architecture design tasks. However, actual code implementation or backend logic is outside this skill's scope.
Teams using component-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/component-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How component-patterns Compares
| Feature / Agent | component-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
React/Next.js component design pattern library. Provides Compound/Render Props/HOC/Custom Hooks patterns, state management strategies (Zustand/React Query/Context), and folder structure conventions as a frontend-dev extension skill. Use for requests like 'component patterns', 'React patterns', 'state management', 'folder structure', 'Custom Hook', 'component separation', and other frontend architecture design tasks. However, actual code implementation or backend logic is outside this skill's scope.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# Component Patterns — React/Next.js Component Design Patterns
A reference for component patterns, state management strategies, and project structure that the frontend-dev agent uses during frontend development.
## Target Agent
`frontend-dev` — Applies this skill's patterns directly to component design and state management.
## Component Design Patterns
### 1. Compound Components
A pattern where parent and child share implicit state.
**Suited for**: Tab, Accordion, Dropdown, Select, and other composite UI
**Structure**: `<Select>` + `<Select.Trigger>` + `<Select.Option>`
**Key Concept**: State sharing via Context, flexible composition through children
### 2. Render Props / Children as Function
Delegates rendering logic externally.
**Suited for**: Data fetching wrappers, mouse/scroll tracking
**Structure**: `<DataLoader render={(data) => <UI data={data} />} />`
**Note**: Prefer Hook pattern when it can replace this
### 3. Custom Hooks (Extraction Pattern)
Extracts state logic into reusable Hooks.
**Suited for**: Form management, API calls, localStorage, debounce
**Naming**: `use` prefix required — `useForm`, `useDebounce`, `useAuth`
### 4. Container/Presentational Separation
Separates data logic (Container) from UI presentation (Presentational).
**Suited for**: Large-scale apps, when testability is needed
**Container**: Data fetch, state management, event handlers
**Presentational**: Renders only from props, functionally pure
### 5. Higher-Order Component (HOC)
Wraps a component to add functionality.
**Suited for**: Auth guards, layout wrappers, error boundaries
**Naming**: `with` prefix — `withAuth`, `withLayout`
**Note**: Prefer Hook/Context when they can replace this
### 6. Headless Component
Provides behavior/state without UI.
**Suited for**: Sharing logic independent of design system
**Examples**: headless `useCombobox`, `useDialog`, `useTable`
## State Management Strategy Selection Guide
| State Type | Recommended Tool | Rationale |
|-----------|-----------------|-----------|
| **UI Local State** | useState, useReducer | Component-internal |
| **Server State** | React Query (TanStack Query) | Caching, refetch, optimistic updates |
| **Global Client State** | Zustand | Concise, minimal boilerplate |
| **Complex Global State** | Zustand + Immer | Immutability convenience |
| **URL State** | nuqs / useSearchParams | Filters, pagination |
| **Form State** | React Hook Form + Zod | Integrated validation |
| **Theme/Language** | Context + Provider | Low change frequency |
### State Placement Decision Flow
```
Should this state be restorable from URL? → URL state
Is it server data? → React Query
Is it shared across multiple components? → Zustand
Is it internal to one component? → useState
Does it have complex transition logic? → useReducer
```
## Next.js App Router Folder Structure
### Recommended Structure (Feature-Based)
```
src/
├── app/ # Next.js App Router
│ ├── (auth)/ # Auth-related route group
│ │ ├── login/page.tsx
│ │ └── register/page.tsx
│ ├── (main)/ # Main route group
│ │ ├── dashboard/page.tsx
│ │ └── settings/page.tsx
│ ├── api/ # API Routes
│ │ └── [...]/route.ts
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home
├── components/
│ ├── ui/ # General UI (Button, Input, Modal)
│ └── features/ # Feature-specific components
│ ├── auth/
│ └── dashboard/
├── hooks/ # Custom Hooks
├── lib/ # Utilities, config
│ ├── api.ts # API client
│ ├── auth.ts # Auth utilities
│ └── utils.ts
├── stores/ # Zustand stores
├── types/ # TypeScript types
└── styles/ # Global styles
```
## Component File Conventions
| Item | Rule |
|------|------|
| File Name | PascalCase: `UserProfile.tsx` |
| Directory | kebab-case: `user-profile/` |
| Index | Re-export via `index.ts` |
| Test | `UserProfile.test.tsx` in same directory |
| Story | `UserProfile.stories.tsx` in same directory |
| Types | Same file or separate `types.ts` |
## Performance Optimization Patterns
| Pattern | When | Tool |
|---------|------|------|
| **Memoization** | Expensive computation, frequent re-renders | `useMemo`, `React.memo` |
| **Lazy Loading** | Initial bundle size | `React.lazy`, `next/dynamic` |
| **Virtualization** | 1000+ item lists | `@tanstack/react-virtual` |
| **Image Optimization** | Image loading | `next/image` |
| **Code Splitting** | Per-route splitting | App Router automatic |
| **Optimistic Updates** | Immediate feedback | React Query `onMutate` |
| **Debounce** | Search, input | `useDeferredValue` or custom hook |
## Error Handling Patterns
### Hierarchical Error Boundaries
```
RootErrorBoundary (global)
└── LayoutErrorBoundary (per section)
└── ComponentErrorFallback (individual)
```
### API Error Handling
| HTTP Status | Client Handling |
|------------|----------------|
| 401 | Auto logout + redirect |
| 403 | Unauthorized UI |
| 404 | Not Found page |
| 422 | Per-field form error display |
| 429 | Retry + wait notice |
| 500 | Generic error UI + retry button |
## Accessibility (a11y) Checklist
- [ ] Alt text on all images
- [ ] Keyboard navigation (Tab, Enter, Escape)
- [ ] ARIA labels (aria-label, role)
- [ ] Color contrast 4.5:1 or above
- [ ] Visible focus indicator
- [ ] Screen reader testing
- [ ] Semantic HTML (button, nav, main, section)Related Skills
risk-response-patterns
risk response strategy pattern library. response-strategist and monitoring-planner agent risk response plan establishto do when reference. 'risk response', 'mitigation strategy', 'response plan' request when usage. However, insurance design legal risk specialistdocument scope outside.
rhetoric-patterns
numbercompany pattern library. speech-writer and debate-preparer agent persuasioncapability speech and buildingto do when reference. 'numbercompany', ' structure', 'persuasion technique' request when usage. However, actual presentation nature training scope outside.
kpi-dashboard-patterns
KPI dashboard design pattern. analyst agent core indicator analysisand executive-summarizer management reporting dashboard compositionto do when reference. 'KPI analysis', 'dashboard design', ' indicator' request when usage. However, actualtime BI whensystem building scope outside.
diagram-patterns
Mermaid diagram pattern library. diagram-maker agent technical document diagram writingto do when reference verifydone pattern . 'diagram pattern', 'Mermaid template', ' diagram pattern' request when usage. However, actual un-degree specialistperson tool work scope outside.
code-example-patterns
technical document code example pattern library. doc-writer agent code example, writingto do when reference. 'code example pattern', ' code writing' request when usage. However, actual code file test execution scope outside.
claim-drafting-patterns
Strategic drafting patterns and claim scope design guide for patent claims. The 'claim-drafter' and 'patent-reviewer' agents must use this skill's drafting patterns, terminology rules, and dependent claim strategies when writing or verifying claims. Used for 'claim drafting', 'claim scope design', 'dependent claim strategy', etc. Note: Overall patent orchestration or prior art search is outside the scope of this skill.
sdk-design-patterns
SDK/API client design patterns: builder pattern, interceptor chain, retry strategy, type-safe design, error handling, and pagination wrapper guide. Use this skill for requests involving 'SDK design', 'client patterns', 'retry strategy', 'interceptor', 'builder pattern', 'SDK error handling', 'type safety', 'SDK architecture', etc. Enhances sdk-developer's SDK design capabilities. Note: API spec parsing, test authoring, and documentation are outside the scope of this skill.
openapi-spec-patterns
OpenAPI 3.x spec analysis patterns, schema normalization, authentication method mapping, pagination/error pattern extraction, and GraphQL/gRPC spec interpretation guide. Use this skill for requests involving 'OpenAPI', 'Swagger', 'spec analysis', 'schema normalization', 'API authentication', 'pagination patterns', 'GraphQL schema', 'gRPC proto', etc. Enhances spec-parser's spec analysis capabilities. Note: SDK code generation and test authoring are outside the scope of this skill.
data-validation-patterns
Migration data validation patterns: row count comparison, checksums, sampling validation, FK integrity, and business rule validation query design guide. Use this skill for requests involving 'data validation', 'migration validation', 'checksum', 'row count comparison', 'integrity validation', 'regression testing', 'Go/No-Go checklist', etc. Enhances validation-engineer's validation design capabilities. Note: schema mapping and rollback planning are outside the scope of this skill.
query-optimization-patterns
SQL/NoSQL query optimization pattern, execution plan analysis, index strategy, N+1 resolution etc. database performance optimization guide. 'query optimization', 'execution plan', 'EXPLAIN', 'index ', 'N+1 ', 'slow query', 'slow query', 'DB performance' etc. database query performance improvement this for. bottleneck-analystand optimization-engineerof DB performance analysis -ize. , before system profilingthis benchmark execution this of scope .
test-design-patterns
Patterns for effective test design, including boundary value analysis, equivalence partitioning, state transition testing, and other systematic test case derivation methodologies. Use this skill for 'test design', 'test case derivation', 'boundary value analysis', 'equivalence partitioning', 'state transition testing', 'pairwise', 'test matrix', and other test design tasks. Enhances the test design capabilities of test-strategist and unit-tester. Note: test infrastructure setup and CI/CD configuration are outside the scope of this skill.
distributed-patterns
Implementation guide and selection matrix for core distributed system patterns (Saga, CQRS, Circuit Breaker, Event Sourcing, etc.). Use this skill for 'distributed transactions', 'Saga pattern', 'CQRS', 'circuit breaker', 'event sourcing', 'distributed patterns', 'compensating transactions', 'eventual consistency', and other distributed system pattern applications. Enhances the distributed system design capabilities of communication-designer and service-architect. Note: infrastructure setup and monitoring configuration are outside the scope of this skill.