/moai-ref-react-patterns
React/Next.js component design patterns, state management strategies, and project structure reference for frontend development. Agent-extending skill that amplifies frontend domain work (spawned via Agent(general-purpose) with frontend instructions) with production-grade React
$ npx -y skills add modu-ai/moai-adk --skill moai-ref-react-patterns --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/moai-ref-react-patterns
Context preview
The summary Claude sees to decide when to auto-load this skill.
React/Next.js component design patterns, state management strategies, and project structure reference for frontend development. Agent-extending skill that amplifies frontend domain work (spawned via Agent(general-purpose) with frontend instructions) with production-grade React
SKILL.md
moai-ref-react-patterns.SKILL.mdname: moai-ref-react-patterns
description: >
React/Next.js component design patterns, state management strategies, and project
structure reference for frontend development. Agent-extending skill that amplifies
frontend domain work (spawned via Agent(general-purpose) with frontend instructions)
with production-grade React patterns.
NOT for: backend API design, database modeling, DevOps, mobile apps.
when_to_use: >
Use for React/Next.js component design patterns: state-management
strategies, hooks, component composition, and project structure.
Amplifies frontend domain work (Agent(general-purpose) with frontend
instructions) with production-grade React patterns.
user-invocable: false
metadata:
version: "1.0.0"
category: "domain"
status: "active"
updated: "2026-03-30"
tags: "react, nextjs, component, patterns, frontend, reference"
# MoAI Extension: Progressive Disclosure
progressive_disclosure:
enabled: true
level1_tokens: 100
level2_tokens: 3000
React Patterns Reference
Target Spawn
Frontend domain work spawned via `Agent(general-purpose)` with frontend instructions - Applies these patterns directly to component design and state management.
Component Design Patterns
1. Compound Components
Parent and child share implicit state via Context.
Suited for: Tab, Accordion, Dropdown, Select Structure: `<Select>` + `<Select.Trigger>` + `<Select.Option>`
2. Custom Hooks (Extraction Pattern)
Extract state logic into reusable hooks.
Suited for: Form management, API calls, localStorage, debounce Naming: `use` prefix required - `useForm`, `useDebounce`, `useAuth`
3. Container/Presentational Separation
Separate data logic (Container) from UI (Presentational).
Suited for: Large apps, when testability is needed Container: Data fetch, state management, event handlers Presentational: Renders only from props, functionally pure
4. Headless Component
Provides behavior/state without UI.
Suited for: Design system-independent logic Examples: headless `useCombobox`, `useDialog`, `useTable`
State Management Selection Guide
| State Type | Tool | Rationale | |-----------|------|-----------| | UI Local | useState, useReducer | Component-internal | | Server State | React Query / TanStack Query | Caching, refetch, optimistic | | Global Client | Zustand | Concise, minimal boilerplate | | Complex Global | Zustand + Immer | Immutability convenience | | URL State | nuqs / useSearchParams | Filters, pagination | | Form State | React Hook Form + Zod | Integrated validation | | Theme/i18n | Context + Provider | Low change frequency |
Decision Flow
Restorable from URL? -> URL state (nuqs)
Server data? -> React Query
Shared across components? -> Zustand
Component-internal? -> useState
Complex transitions? -> useReducer
Next.js App Router Structure
src/
├── app/ # App Router
│ ├── (auth)/ # Auth route group
│ │ ├── login/page.tsx
│ │ └── register/page.tsx
│ ├── (main)/ # Main route group
│ │ ├── dashboard/page.tsx
│ │ └── settings/page.tsx
│ ├── api/ # API Routes
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home
├── components/
│ ├── ui/ # Base UI (Button, Input, Modal)
│ └── features/ # Feature components
│ ├── auth/
│ └── dashboard/
├── hooks/ # Custom hooks
├── lib/ # Utilities, config
├── stores/ # Zustand stores
├── types/ # TypeScript types
└── styles/ # Global styles
Component Quality Standards
| Item | Standard | |------|----------| | Component Size | Under 200 lines (split if exceeded) | | Props | 5 or fewer (group into object if exceeded) | | Custom Hooks | Always extract when reusing logic | | Error Boundaries | Set at the page level | | Loading States | Provide loading UI for all async ops | | Form Validation | Validate on both client and server |
Performance Patterns
| Pattern | When | Tool | |---------|------|------| | Memoization | Expensive computation | `useMemo`, `React.memo` | | Lazy Loading | Bundle size | `React.lazy`, `next/dynamic` | | Virtualization | 1000+ item lists | `@tanstack/react-virtual` | | Image Optimization | Image loading | `next/image` | | Optimistic Updates | Immediate feedback | React Query `onMutate` | | Debounce | Search, input | `useDeferredValue` or custom hook |
Error Handling
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 | | 429 | Retry + wait notice | | 500 | Generic error + retry button |
Accessibility 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
- [ ] Semantic HTML (button, nav, main, section)
<!-- moai:evolvable-start id="rationalizations" -->
Common Rationalizations
| Rationalization | Reality | |---|---| | "useEffect is fine for data fetching in React 19" | React 19 provides use() and server components for data fetching. useEffect for fetch is a legacy pattern that causes waterfalls. | | "Global state is simpler than prop drilling" | Global state couples distant components. Prop drilling or composition via children is more predictable and testable. | | "I will add TypeScript types later" | Untyped components accumulate any-typed callers. Retrofitting types into a used component is much harder than starting typed. | | "This component does not need memoization" | Premature memoization is waste, but components rendering lists or expensive trees should be profiled, not assu
Read more
name: moai-ref-react-patterns description: > React/Next.js component design patterns, state management strategies, and project structure reference for frontend development. Agent-extending skill that amplifies frontend domain work (spawned via Agent(general-purpose) with frontend instructions) with production-grade React patterns. NOT for: backend API design, database modeling, DevOps, mobile apps. when_to_use: > Use for React/Next.js component design patterns: state-management strategies, hooks, component composition, and project structure. Amplifies frontend domain work (Agent(general-purpose) with frontend instructions) with production-grade React patterns. user-invocable: false metadata: version: "1.0.0" category: "domain" status: "active" updated: "2026-03-30" tags: "react, nextjs, component, patterns, frontend, reference" # MoAI Extension: Progressive Disclosure progressive_disclosure: enabled: true level1_tokens: 100 level2_tokens: 3000
React Patterns Reference
Target Spawn
Frontend domain work spawned via `Agent(general-purpose)` with frontend instructions - Applies these patterns directly to component design and state management.
Component Design Patterns
1. Compound Components
Parent and child share implicit state via Context.
Suited for: Tab, Accordion, Dropdown, Select Structure: `<Select>` + `<Select.Trigger>` + `<Select.Option>`
2. Custom Hooks (Extraction Pattern)
Extract state logic into reusable hooks.
Suited for: Form management, API calls, localStorage, debounce Naming: `use` prefix required - `useForm`, `useDebounce`, `useAuth`
3. Container/Presentational Separation
Separate data logic (Container) from UI (Presentational).
Suited for: Large apps, when testability is needed Container: Data fetch, state management, event handlers Presentational: Renders only from props, functionally pure
4. Headless Component
Provides behavior/state without UI.
Suited for: Design system-independent logic Examples: headless `useCombobox`, `useDialog`, `useTable`
State Management Selection Guide
| State Type | Tool | Rationale | |-----------|------|-----------| | UI Local | useState, useReducer | Component-internal | | Server State | React Query / TanStack Query | Caching, refetch, optimistic | | Global Client | Zustand | Concise, minimal boilerplate | | Complex Global | Zustand + Immer | Immutability convenience | | URL State | nuqs / useSearchParams | Filters, pagination | | Form State | React Hook Form + Zod | Integrated validation | | Theme/i18n | Context + Provider | Low change frequency |
Decision Flow
Restorable from URL? -> URL state (nuqs) Server data? -> React Query Shared across components? -> Zustand Component-internal? -> useState Complex transitions? -> useReducer
Next.js App Router Structure
src/ ├── app/ # App Router │ ├── (auth)/ # Auth route group │ │ ├── login/page.tsx │ │ └── register/page.tsx │ ├── (main)/ # Main route group │ │ ├── dashboard/page.tsx │ │ └── settings/page.tsx │ ├── api/ # API Routes │ ├── layout.tsx # Root layout │ └── page.tsx # Home ├── components/ │ ├── ui/ # Base UI (Button, Input, Modal) │ └── features/ # Feature components │ ├── auth/ │ └── dashboard/ ├── hooks/ # Custom hooks ├── lib/ # Utilities, config ├── stores/ # Zustand stores ├── types/ # TypeScript types └── styles/ # Global styles
Component Quality Standards
| Item | Standard | |------|----------| | Component Size | Under 200 lines (split if exceeded) | | Props | 5 or fewer (group into object if exceeded) | | Custom Hooks | Always extract when reusing logic | | Error Boundaries | Set at the page level | | Loading States | Provide loading UI for all async ops | | Form Validation | Validate on both client and server |
Performance Patterns
| Pattern | When | Tool | |---------|------|------| | Memoization | Expensive computation | `useMemo`, `React.memo` | | Lazy Loading | Bundle size | `React.lazy`, `next/dynamic` | | Virtualization | 1000+ item lists | `@tanstack/react-virtual` | | Image Optimization | Image loading | `next/image` | | Optimistic Updates | Immediate feedback | React Query `onMutate` | | Debounce | Search, input | `useDeferredValue` or custom hook |
Error Handling
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 | | 429 | Retry + wait notice | | 500 | Generic error + retry button |
Accessibility 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
- [ ] Semantic HTML (button, nav, main, section)
<!-- moai:evolvable-start id="rationalizations" -->
Common Rationalizations
| Rationalization | Reality | |---|---| | "useEffect is fine for data fetching in React 19" | React 19 provides use() and server components for data fetching. useEffect for fetch is a legacy pattern that causes waterfalls. | | "Global state is simpler than prop drilling" | Global state couples distant components. Prop drilling or composition via children is more predictable and testable. | | "I will add TypeScript types later" | Untyped components accumulate any-typed callers. Retrofitting types into a used component is much harder than starting typed. | | "This component does not need memoization" | Premature memoization is waste, but components rendering lists or expensive trees should be profiled, not assu
Agentic development harness for Claude Code — SPEC-driven plan/run/sync, TRUST 5 quality gates, model+effort routing, and Claude×GLM multi-LLM cost control. Single Go binary, 16 languages, zero deps.
Repo: modu-ai/moai-adk
Other skills on moai-adk.
- /hns-lsel-applier
Local Self-Evolution Loop (LSEL) APPLY engine — the playback-only consumer of approved decision.json records that drives `.moai/hooks/lsel-apply.sh` for the GOOS-local PROPOSE→APPLY seam closure (SPEC-LSEL-LOCAL-EVOLUTION-001 M3). Reads an approved decision.json, validates the
Open skill - /hns-lsel-curator
Local Self-Evolution Loop (LSEL) curator — the CLUSTER + drain engine for the GOOS-local PROPOSE→APPLY seam closure (SPEC-LSEL-LOCAL-EVOLUTION-001). Companion-offset drain of .moai/lessons-inbox.jsonl with a drain-side severity filter that drops the ~65% Bash-timeout/sandbox
Open skill - /hns-moaiadk-best-practices
moai-adk-go best-practices reference for the 4 harness specialists (cli-template-specialist, quality-specialist, workflow-specialist, hook-ci-specialist). Covers TRUST 5 gates, Go test isolation (t.TempDir, no OTEL env in parallel tests), hardcoding-prevention rules (env
Open skill - /hns-moaiadk-dev-reference
moai-adk-go local dev reference — version management/release process (sec 5), shell-script hook development (sec 7), build & dev commands (sec 10). Load only when performing these specific tasks.
Open skill - /hns-moaiadk-patterns
moai-adk-go domain-patterns reference for the 4 harness specialists (cli-template-specialist, quality-specialist, workflow-specialist, hook-ci-specialist). Covers the CLI/template/config/hook/spec subsystem architecture, key source paths, the Pipeline specialist delegation map,
Open skill - /hns-oss-docs-i18n-rules
HARD i18n rules digest for the oss-docs harness specialists working on moai-adk-go README 4-locale set and the docs-site (adk.mo.ai.kr). Covers the canonical-locale chains, the 4-locale same-PR obligation, Mermaid TD-only, the no-emoji + icon-shortcode rule, emphasis-marker
Open skill

