Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

typescript-react-patterns

БесплатноБез исполняемых скриптовНе проверен

TypeScript best practices for React development. Use when writing typed React components, hooks, events, refs, or generic components. Triggers on tasks…

AsyrafHussinот AsyrafHussin★ 112 звёзд на GitHub4 установки в других каталогах

Об этом скилле

TypeScript React Patterns

Type-safe React with TypeScript. Contains 36 rules across 7 categories covering component typing, hooks, event handling, refs, generics, context, and utility types. Targets React 19.x (@types/react 19) and TypeScript 5.x–7.x.

Metadata

  • Version: 2.1.0
  • Updated: November 2026
  • Targets: React 19.x, @types/react 19, TypeScript 5.x–7.x
  • Rule Count: 36 rules across 7 categories
  • License: MIT

When to Apply

Reference these guidelines when:

  • Typing React component props
  • Creating custom hooks with TypeScript
  • Handling events with proper types
  • Working with refs (DOM, mutable, imperative)
  • Building generic, reusable components
  • Setting up typed Context providers
  • Fixing TypeScript errors in React code
  • Typing React 19 Actions (useActionState, useOptimistic, use) and useEffectEvent
  • Migrating React 18 types (forwardRef, defaultProps, global JSX, useRef()) or a tsconfig to TypeScript 7

Rule Categories by Priority

Priority Category Impact Prefix
1 Component Typing CRITICAL comp-
2 Hook Typing CRITICAL hook-
3 Event Handling HIGH event-
4 Ref Typing HIGH ref-
5 Generic Components MEDIUM generic-
6 Context & State MEDIUM ctx-
7 Utility Types LOW util-

Quick Reference

1. Component Typing (CRITICAL)

  • comp-props-interface - Use interface for props, type for unions
  • comp-children-types - Correct children typing (ReactNode, ReactElement)
  • comp-default-props - Default props with destructuring defaults
  • comp-forward-ref - Ref as a prop in React 19 (forwardRef only for React 18 libraries)
  • comp-polymorphic - Polymorphic "as" prop typing
  • comp-fc-vs-function - Function declaration vs React.FC
  • comp-display-name - Display names for debugging
  • comp-rest-props - Spreading rest props with proper types

2. Hook Typing (CRITICAL)

  • hook-usestate - useState with proper generic types
  • hook-useref - useRef for DOM elements and mutable values
  • hook-use-reducer - useReducer with discriminated union actions
  • hook-use-callback - useCallback with typed parameters
  • hook-use-memo - useMemo with typed return values
  • hook-use-context - useContext with null checking
  • hook-custom-hooks - Custom hook return types
  • hook-generic-hooks - Generic custom hooks
  • hook-use-action-state - useActionState, useOptimistic and use() typing
  • hook-use-effect-event - useEffectEvent typing (React 19.2)

3. Event Handling (HIGH)

  • event-handler-types - Event handler type patterns
  • event-click-handler - Click event typing
  • event-form - Form event handling (SubmitEvent, ChangeEvent, select)
  • event-keyboard - Keyboard event types

4. Ref Typing (HIGH)

  • ref-dom-elements - useRef with specific HTML element types
  • ref-callback - Callback ref pattern for DOM measurement
  • ref-imperative-handle - useImperativeHandle typing

5. Generic Components (MEDIUM)

  • generic-list - Generic list components
  • generic-select - Generic select/dropdown
  • generic-table - Generic table with typed columns
  • generic-constraints - Generic constraints with extends

6. Context & State (MEDIUM)

  • ctx-create - Creating typed context
  • ctx-provider - Provider pattern with null check hook (<Context value>)
  • ctx-reducer - Context with useReducer

7. Utility Types (LOW)

  • util-component-props - ComponentPropsWithoutRef for HTML props
  • util-pick-omit - Pick, Omit, Partial for prop derivation
  • util-discriminated-unions - Discriminated unions for state machines
  • util-tsconfig - tsconfig for React with TypeScript 7

Essential Patterns

Component Props

interface ButtonProps {
  variant: 'primary' | 'secondary' | 'danger'
  size?: 'sm' | 'md' | 'lg'
  children: React.ReactNode
  onClick?: () => void
}

function Button({ variant, size = 'md', children, onClick }: ButtonProps) {
  return (
    <button className={`btn-${variant} btn-${size}`} onClick={onClick}>
      {children}
    </button>
  )
}

Typed Context with Null Check

interface AuthContextType {
  user: User | null
  login: (credentials: Credentials) => Promise<void>
  logout: () => void
}

const AuthContext = createContext<AuthContextType | null>(null)

function useAuth() {
  const context = useContext(AuthContext)
  if (!context) throw new Error('useAuth must be used within AuthProvider')
  return context
}

Generic Component

interface ListProps<T> {
  items: T[]
  renderItem: (item: T) => React.ReactNode
  keyExtractor: (item: T) => string
}

function List<T>({ items, renderItem, keyExtractor }: ListProps<T>) {
  return <ul>{items.map(item => <li key={keyExtractor(item)}>{renderItem(item)}</li>)}</ul>
}

How to Use

Read individual rule files for detailed explanations:

rules/comp-props-interface.md
rules/hook-usestate.md
rules/event-form.md
rule
Полный SKILL.md на GitHub

Установить typescript-react-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdREADME.mdmetadata.jsonrules/_sections.mdrules/_template.mdrules/comp-children-types.mdrules/comp-default-props.mdrules/comp-display-name.mdrules/comp-fc-vs-function.mdrules/comp-forward-ref.mdrules/comp-polymorphic.mdrules/comp-props-interface.mdrules/comp-rest-props.mdrules/ctx-create.mdrules/ctx-provider.mdrules/ctx-reducer.mdrules/event-click-handler.mdrules/event-form.mdrules/event-handler-types.mdrules/event-keyboard.mdrules/generic-constraints.mdrules/generic-list.mdrules/generic-select.mdrules/generic-table.mdrules/hook-custom-hooks.mdrules/hook-generic-hooks.mdrules/hook-use-action-state.mdrules/hook-use-callback.mdrules/hook-use-context.mdrules/hook-use-effect-event.mdrules/hook-use-memo.mdrules/hook-use-reducer.mdrules/hook-useref.mdrules/hook-usestate.mdrules/ref-callback.mdrules/ref-dom-elements.mdrules/ref-imperative-handle.mdrules/util-component-props.mdrules/util-discriminated-unions.mdrules/util-pick-omit.md

FAQ

Что делает скилл typescript-react-patterns?

TypeScript best practices for React development. Use when writing typed React components, hooks, events, refs, or generic components. Triggers on tasks involving TypeScript errors, type definitions, props typing, or type-safe React patterns.

Как установить скилл typescript-react-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл typescript-react-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить typescript-react-patterns с