typescript-react-patterns▌
asyrafhussin/agent-skills · updated Apr 8, 2026
Type-safe React with TypeScript. Contains 33 rules across 7 categories covering component typing, hooks, event handling, refs, generics, context, and utility types.
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
| 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 unionscomp-children-types- Correct children typing (ReactNode, ReactElement)comp-default-props- Default props with destructuring defaultscomp-forward-ref- Typing forwardRef componentscomp-polymorphic- Polymorphic "as" prop typingcomp-fc-vs-function- Function declaration vs React.FCcomp-display-name- Display names for debuggingcomp-rest-props- Spreading rest props with proper types
2. Hook Typing (CRITICAL)
hook-usestate- useState with proper generic typeshook-useref- useRef for DOM elements and mutable valueshook-use-reducer- useReducer with discriminated union actionshook-use-callback- useCallback with typed parametershook-use-memo- useMemo with typed return valueshook-use-context- useContext with null checkinghook-custom-hooks- Custom hook return typeshook-generic-hooks- Generic custom hooks
3. Event Handling (HIGH)
event-handler-types- Event handler type patternsevent-click-handler- Click event typingevent-form- Form event handling (submit, change, select)event-keyboard- Keyboard event types
4. Ref Typing (HIGH)
ref-dom-elements- useRef with specific HTML element typesref-callback- Callback ref pattern for DOM measurementref-imperative-handle- useImperativeHandle typing
5. Generic Components (MEDIUM)
generic-list- Generic list componentsgeneric-select- Generic select/dropdowngeneric-table- Generic table with typed columnsgeneric-constraints- Generic constraints with extends
6. Context & State (MEDIUM)
ctx-create- Creating typed contextctx-provider- Provider pattern with null check hookctx-reducer- Context with useReducer
7. Utility Types (LOW)
util-component-props- ComponentPropsWithoutRef for HTML propsutil-pick-omit- Pick, Omit, Partial for prop derivationutil-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
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★40 reviews- ★★★★★Noor Torres· Dec 20, 2024
We added typescript-react-patterns from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Ganesh Mohane· Dec 16, 2024
Keeps context tight: typescript-react-patterns is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Camila Harris· Dec 16, 2024
I recommend typescript-react-patterns for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Diego Ramirez· Dec 4, 2024
Keeps context tight: typescript-react-patterns is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Camila Martin· Nov 23, 2024
Registry listing for typescript-react-patterns matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Lucas Dixit· Nov 15, 2024
Useful defaults in typescript-react-patterns — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Lucas Desai· Nov 11, 2024
Solid pick for teams standardizing on skills: typescript-react-patterns is focused, and the summary matches what you get after install.
- ★★★★★Rahul Santra· Nov 7, 2024
Registry listing for typescript-react-patterns matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Pratham Ware· Oct 26, 2024
typescript-react-patterns reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Ren Iyer· Oct 14, 2024
typescript-react-patterns reduced setup friction for our internal harness; good balance of opinion and flexibility.
showing 1-10 of 40