typescript-react-nextjs-patterns
Production-grade TypeScript reference for React & Next.js frontend development. Covers type narrowing, component Props, generic hooks, discriminated unions…
от skillmds★ 42 звезды на GitHub
Установить typescript-react-nextjs-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
TypeScript for React & Next.js — Agent Skill
A structured reference for AI coding agents assisting frontend engineers with TypeScript, React, and Next.js in production environments.
Agent Behavior Rules
Before answering, always verify:
- Server or client? Server Components, Server Actions, and Route Handlers have different type constraints than
"use client"components. - Runtime validation needed? Static types do NOT validate API responses, URL params, form data, or localStorage. Data crossing a trust boundary requires Zod or equivalent.
- App Router or Pages Router? Patterns differ significantly. If unclear, ask.
- TypeScript version?
satisfiesneeds 5.0+,NoInfer5.4+, inferred type predicates 5.5+. TS 6.0 is the final JS-based compiler; TS 7 is the Go-native rewrite — ~10x faster, same language, but tooling that consumes the old compiler API may lag. - Next.js version?
paramsis aPromisein 15+. Caching model changed in 16+ ("use cache"), and 16 renamesmiddleware.ts→proxy.ts(Node runtime). - React version? 19 makes
refa regular prop (forwardRefdeprecated), renders<Context>directly, and replacesuseFormStatewithuseActionState.useEffectEventand<Activity>need 19.2+.
Assumptions the agent must NOT make:
- That API responses match their TypeScript types at runtime
- That
searchParamsvalues are the expected type (they are alwaysstring | string[] | undefined) - That
anyin existing code is intentional - That a type assertion (
as) is justified without checking context - That server-only imports are safe in client components
- That
useEffectdependencies in existing code are correct
When uncertain:
- State tradeoffs explicitly rather than picking one approach silently
- Mark unstable or version-dependent patterns as such
- Distinguish: [HARD RULE] (violating causes bugs) / [DEFAULT] (override with reason) / [SITUATIONAL] (depends on context)
After context compaction:
If this session was compacted and the rules content survives only as a summary:
- Do NOT answer from the summary — it drops the reasoning, examples, and edge cases.
- Re-read the relevant file from the Decision Guide below before continuing. One file read is enough; this hub is deliberately thin so recovery is cheap.
- If mid-task and unsure which file applies, re-read
HARD-RULES.mdfirst — every non-negotiable rule in compressed form.
Decision Guide
Quick: What pattern should I use?
| Situation | Start here |
|---|---|
| Typing component Props, children, events, refs | → react-typescript-patterns.md |
Narrowing unions, unknown, type guards, utility types |
→ typescript-core.md |
| Next.js params, searchParams, Server Actions, RSC boundary | → nextjs-typescript.md |
| Discriminated unions, conditional props, compound components | → component-patterns.md |
| API responses, fetch typing, TanStack Query, caching | → data-fetching-and-api-types.md |
| Form state, validation, controlled vs uncontrolled | → forms-and-validation.md |
| Local state vs context vs server state vs Zustand | → state-management.md |
| Re-renders, memoization, accessibility | → performance-and-accessibility.md |
| Type errors, hydration, stale state, effect bugs | → debugging-checklists.md (hub) + playbooks/ |
| PR review, risk vs preference, architecture smells | → code-review-rules.md |
| Common mistakes, cargo-cult patterns | → anti-patterns.md |
Flowchart: Is this data safe to use?
Data comes from...
├─ Inside the app (useState, useReducer, computed)
│ → Static typing is sufficient. No runtime validation needed.
│
├─ Outside the app (API, URL, FormData, localStorage, postMessage)
│ → [HARD RULE] Validate at runtime. Use Zod or equivalent.
│ │
│ ├─ API response → schema.parse(await res.json())
│ ├─ URL params → schema.parse(searchParams)
│ ├─ FormData → schema.safeParse({ field: formData.get('field') })
│ ├─ localStorage → schema.safeParse(JSON.parse(stored))
│ └─ postMessage → schema.safeParse(event.data)
│
└─ Third-party library callback
→ Check library types. Add runtime guard if types seem wrong.
Flowchart: Where should this state live?
Is this data from a server/API?
├─ Yes → TanStack Query (NOT useState). See data-fetching-and-api-types.md
│
└─ No → Is it shareable via URL? (filters, page, sort)
├─ Yes → searchParams or nuqs. See state-management.md
│
└─ No → How many components need it?
├─ 1 component → useState or useReducer
├─ 2-3 in same tree → Lift state up (props)
└─ Many across trees → How often does it change?
├─ Rarely (theme, locale, auth) → Context
└─ Often (cart, notifications) → Zustand with selectors
Flowchart: Should I memoize this?
Is there a measured performance problem?
├─ No → Don't memoize. Stop here.
│
└─ Yes → Can you restructure instead?
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- HARD-RULES.md
- LICENSE
- README.ko.md
- README.md
- playbooks/effect-dependency-bugs.md
- playbooks/hydration-issues.md
- playbooks/type-error-debugging.md
FAQ
Что делает скилл typescript-react-nextjs-patterns?
Production-grade TypeScript reference for React & Next.js frontend development. Covers type narrowing, component Props, generic hooks, discriminated unions, as const, satisfies, Zod validation, TanStack Query, server/client boundaries, forms, state management, performance, accessibility, debugging, and code review. Use when the user works with TypeScript in React or Next.js: type errors, Props design, generics, API typing, SSR/CSR boundaries, hydration issues, form validation, state management, performance, or code review. Also use for "how should I type this?", "why does this type error happen?", or any architectural decision involving TypeScript in a frontend context.
Как установить скилл typescript-react-nextjs-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл typescript-react-nextjs-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…