react-types

Enforce TypeScript typing best practices for React components, props, and events.

Updated Feb 5, 2026
One-click install
npx skills add https://github.com/Objective-Arts/lens --skill react-types
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-types
Source: https://github.com/Objective-Arts/lens/tree/main/canon/javascript/react-types
Command: npx skills add https://github.com/Objective-Arts/lens --skill react-types

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more robust, type-safe React components by enforcing best practices for TypeScript typing in React applications.

Core Features & Use Cases

  • Component Props: Guides on using interfaces vs. inline types for props.
  • Event Handlers: Provides correct typing for various React event handlers (e.g., MouseEvent, ChangeEvent).
  • State and Refs: Offers patterns for typing useState and useRef effectively.
  • Generic Components: Demonstrates how to create type-safe generic components and hooks.
  • Use Case: When typing a new React component, this Skill ensures you use ReactNode for children, the correct event types for user interactions, and interface for props, preventing common runtime errors and improving code maintainability.

Quick Start

Apply Matt Pocock's React TypeScript patterns to ensure correct typing for components, hooks, events, and refs.

Frequently Asked Questions about react-types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I type React event handlers to avoid using `any`?

To type React event handlers without `any`, use specific event types like `MouseEvent` or `ChangeEvent` from React's type definitions. This enforces type safety for user interactions and prevents common runtime errors in your components.

What's the best way to type React component props and children?

The best way to type React component props is by using `interface` declarations rather than inline types, and typing children as `ReactNode`. This approach optimizes for clarity, safety, and maintainability in your React TypeScript projects.

How do I type `useState` and `useRef` hooks in TypeScript?

Typing `useState` and `useRef` involves providing explicit generic type arguments to the hooks. This ensures correct state management and ref typing patterns, preventing incorrect type assignments during component development.

How do you create type-safe generic React components and hooks?

Creating type-safe generic React components and hooks requires defining generic type parameters in your function signatures. This allows your component development to enforce flexible but strictly typed patterns across different data structures.

Why should I use an interface instead of a type alias for React component props?

Using an `interface` for React component props instead of an inline type ensures better code maintainability and clarity. It enforces strict typing patterns and allows for safer declaration merging when structuring complex React TypeScript applications.

Do I need TypeScript to enforce safety in React state management and context?

Using TypeScript is necessary to enforce safety in React state management and context, as it addresses common anti-patterns like incorrect typing for context values. This prevents runtime errors and ensures robust component development.