ConfigsMar 29, 2026·1 min read

Cursor Rules: React + TypeScript

Cursor rules for React with TypeScript. Enforces functional components, hooks patterns, proper typing, component composition, and testing conventions.

TO
TokRepo精选 · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

Create .cursor/rules/react-ts.mdc in your project root.


Intro

Teaches Cursor AI to write production-quality React + TypeScript code. Covers component patterns, hooks, state management, performance optimization, and testing.

Best for: React developers using Cursor IDE Works with: Cursor


Rules Include

Components

  • Functional components only (no class components)
  • Props interfaces (not type) with descriptive names
  • React.FC avoided — use explicit return types
  • Component files: one component per file, named exports

Hooks

  • Custom hooks for shared logic (prefix with use)
  • useMemo/useCallback only for measured performance issues
  • useReducer for complex state, useState for simple

TypeScript

  • Strict mode enabled
  • Discriminated unions for component variants
  • Generic components when type flexibility needed
  • as const for literal types

Testing

  • React Testing Library (not Enzyme)
  • Test behavior, not implementation
  • userEvent over fireEvent

🙏

Source & Thanks

Curated from the cursor.directory community.

Related Assets