Configs2026年3月29日·1 分钟阅读

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
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

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


介绍

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

🙏

来源与感谢

Curated from the cursor.directory community.

相关资产