Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
asyrafhussin avatar

Typescript React Patterns

  • 477 installs
  • 60 repo stars
  • Updated May 16, 2026
  • asyrafhussin/agent-skills

typescript-react-patterns is an agent skill that applies 33 TypeScript typing rules across 7 categories for developers writing type-safe React components, hooks, events, refs, generics, and context in modern UI codebases

About

typescript-react-patterns is an agent skill from asyrafhussin/agent-skills version 2.0.0 that codifies 33 TypeScript rules across 7 categories for React development. Categories span component typing (props interfaces, forwardRef, polymorphic as props), hook typing (useState, useReducer, useCallback, custom hooks), event handlers, ref patterns including useImperativeHandle, generic list/select/table components, typed Context providers, and utility types like ComponentPropsWithoutRef and discriminated unions. Developers reach for typescript-react-patterns when fixing TypeScript errors in React code, typing new components and hooks, or standardizing folder-level patterns during agent-assisted UI work. Each rule uses prefixed identifiers such as comp-props-interface and hook-use-reducer with detailed explanations in individual rules/ files and a compiled AGENTS.md reference. Priority ranks component and hook typing as CRITICAL, event and ref typing as HIGH, and utility types as LOW impact guidance.

  • Component and hook patterns
  • Strict TypeScript typing
  • Reusable UI architecture
  • Agent-friendly React conventions
  • Saas and extension UI fit

Typescript React Patterns by the numbers

  • 477 all-time installs (skills.sh)
  • Ranked #631 of 2,245 Frontend Development skills by installs in the Skillselion catalog
  • Data as of Aug 3, 2026 (Skillselion catalog sync)
npx skills add https://github.com/asyrafhussin/agent-skills --skill typescript-react-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs477
repo stars60
Last updatedMay 16, 2026
Repositoryasyrafhussin/agent-skills

How do you type React components and hooks in TypeScript?

Apply proven TypeScript and React patterns for components, hooks, state, typing, and folder structure while building modern UI features in agent-assisted coding sessions.

Who is it for?

React TypeScript developers who want consistent, rule-based typing for components, hooks, and context during agent-assisted feature work.

Skip if: Vue, Svelte, or plain JavaScript React projects where TypeScript strict typing patterns are not required or used.

When should I use this skill?

User writes typed React components or hooks, hits TypeScript errors in React code, or asks for props, event, ref, or generic component typing patterns.

What you get

Type-safe React component props, hook signatures, event handlers, ref types, generic components, and context providers aligned to 33 rules.

  • Typed component and hook implementations
  • Context provider patterns
  • Generic reusable component types

By the numbers

  • Version 2.0.0 with 33 rules across 7 categories
  • Rule prefixes span comp-, hook-, event-, ref-, generic-, ctx-, and util- namespaces

Files

SKILL.mdMarkdownGitHub ↗

TypeScript React Patterns

Type-safe React with TypeScript. Contains 33 rules across 7 categories covering component typing, hooks, event handling, refs, generics, context, and utility types.

Metadata

  • Version: 2.0.0
  • Rule Count: 33 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

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Component TypingCRITICALcomp-
2Hook TypingCRITICALhook-
3Event HandlingHIGHevent-
4Ref TypingHIGHref-
5Generic ComponentsMEDIUMgeneric-
6Context & StateMEDIUMctx-
7Utility TypesLOWutil-

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 - Typing forwardRef components
  • 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

3. Event Handling (HIGH)

  • event-handler-types - Event handler type patterns
  • event-click-handler - Click event typing
  • event-form - Form event handling (submit, change, 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
  • 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

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
rules/ref-dom-elements.md
rules/util-discriminated-unions.md

References

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Related skills

How it compares

Pick typescript-react-patterns over generic TypeScript skills when React-specific props, hooks, refs, and generic component typing rules are the bottleneck.

FAQ

How many rules does typescript-react-patterns include?

typescript-react-patterns version 2.0.0 includes 33 rules organized into 7 categories: component typing, hook typing, event handling, ref typing, generic components, context and state, and utility types.

When should typescript-react-patterns be used?

typescript-react-patterns applies when typing React component props, custom hooks, event handlers, refs, generic reusable components, or fixing TypeScript errors in React UI code during development.

Frontend Developmentfrontendintegrationstesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.