02-react-typescript

02-react-typescript is a cursor rule for Cursor from 2154355737/JieShenSheQu. It costs 0 tokens per session (2,158 once invoked), scanned A, original, MIT.

Development rules for building a mobile app with React, a user-interface library, and TypeScript, a language that adds type checking to JavaScript. They cover function components, typed component inputs, reusable Hooks, and shared state.

In plain words
What is it for?
Use them when creating or editing React components, defining Props, writing custom Hooks such as authentication helpers, or managing shared application state.
Why use it?
They give an AI coding assistant consistent patterns for defining components and handling data. This helps reduce unclear interfaces and inconsistent state management.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/2154355737/jieshenshequ/02-react-typescript
Clone the repo
git clone --depth 1 https://github.com/2154355737/JieShenSheQu

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 02-react-typescript

README.md
[![agentmods](https://agentmods.dev/badge/rules/2154355737/jieshenshequ/02-react-typescript.svg)](https://agentmods.dev/rules/2154355737/jieshenshequ/02-react-typescript)
Your own site
<a href="https://agentmods.dev/rules/2154355737/jieshenshequ/02-react-typescript"><img src="https://agentmods.dev/badge/rules/2154355737/jieshenshequ/02-react-typescript.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,158 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02158
Opus 5 $0.00000 $0.01079
Sonnet 5 $0.00000 $0.00432
Haiku 4.5 $0.00000 $0.00216

Measured 3d ago against content hash 812ccc899d59, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

02-react-typescript scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

App_v2/jieshengshequ-app/.cursor/rules/02-react-typescript.mdc · 355 lines

How it starts

The opening of the file, as written. The whole thing — 355 lines — stays where its author put it; the contents beside it link to each section on GitHub.

React + TypeScript 开发规范

📋 组件开发规范

1. 组件定义

// ✅ 推荐: 使用函数组件 + TypeScript
interface UserProfileProps {
  userId: string;
  onUpdate?: (user: User) => void;
}

export const UserProfile: React.FC<UserProfileProps> = ({ userId, onUpdate }) => {
  const [loading, setLoading] = useState(false);
  
  return <div>...</div>;
};

2. Props类型定义

  • 总是为Props定义接口
  • 使用可选属性标记 ?
  • 提供默认值
interface ButtonProps {
  label: string;
  variant?: 'primary' | 'secondary' | 'outline';
  disabled?: boolean;
  onClick?: () => void;
}

export const Button: React.FC<ButtonProps> = ({ 
  label, 
  variant = 'primary',
  disabled = false,
  onClick 
}) => {
  return <button className={`btn-${variant}`} disabled={disabled} onClick={onClick}>
    {label}
  </button>;
};

3. Hooks使用规范

// ✅ 推荐: 自定义Hook
export const useAuth = () => {
  const context = useContext(AuthContext);
  if (!context) {
    throw new Error('useAuth must be used within AuthProvider');
  }
  return context;
};

// 在组件中使用
const MyComponent: React.FC = () => {
  const { user, login, logout } = useAuth();
  // ...
};

4. 状态管理

// ✅ 推荐: 使用Context API
interface AuthContextType {
  user: User | null;
  isAuthenticated: boolean;
  login: (token: string) => Promise<void>;
  logout: () => void;
}

export const AuthContext = createContext<AuthContextType | undefined>(undefined);

export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
  const [user, setUser] = useState<User | null>(null);
  
  const login = async (token: string) => {
    // 实现登录逻辑
  };
  
  return (
    <AuthContext.Provider value={{ user, isAuthenticated: !!user, login, logout }}>
      {children}
    </AuthContext.Provider>
  );
};

5. 错误处理

// ✅ 推荐: 使用错误边界
export const ErrorBoundary: React.FC<{ children: ReactNode }> = ({ children }) => {
  const [hasError, setHasError] = useState(false);
  
  useEffect(() => {
    const handleError = (error: Error) => {
      console.error('Error caught:', error);
      setHasError(true);
    };
    
    window.addEventListener('error', handleError);
    return () => window.removeEventListener('error', handleError);
  }, []);
  
  if (hasError) {
    return <div>Something went wrong</div>;
  }
  
  return <>{children}</>;
};

Read the full file on GitHub · 355 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 355 lines · 2,158 tokens per session scan A 812ccc899d59

Subscribe to this mod's changes

02-react-typescript is a cursor rule published in the GitHub repository 2154355737/JieShenSheQu (2 stars, last pushed 10mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,158 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.