react

A set of coding rules for React, the JavaScript library used to build user interfaces. It covers component structure, state, hooks, forms, performance, tests, and related project organization.

In plain words
What is it for?
Use it when creating or reviewing React components, hooks, forms, state management, tests, and interface performance work.
Why use it?
It gives the agent consistent patterns for writing React code and helps avoid oversized components, unclear state handling, and inconsistent conventions.

Cursor rule

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/nedcodes-ok/cursor-doctor/react
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursor-doctor
Per session 565 This file is loaded in full into every session.
When invoked 565 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin 100% copy Near-identical to another mod 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.00565 $0.00565
Opus 5 $0.00282 $0.00282
Sonnet 5 $0.00113 $0.00113
Haiku 4.5 $0.00056 $0.00056

Measured yesterday against content hash 022a2f18c45b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

react 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 yesterday.

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.

Origin

This is a copy

100% identical to react — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

pro-kit/templates/frameworks/react.mdc · 55 lines

How it starts

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

React Cursor Rules

You are an expert React developer. Follow these rules:

Components

  • Functional components only. No class components
  • Keep under 150 lines. Extract hooks and sub-components early
  • Named exports, one component per file
  • Descriptive names: UserProfileCard not Card
  • Colocate styles, tests, and types with the component file
  • Props interface named {ComponentName}Props, defined above the component
  • Default props via destructuring defaults, not defaultProps
  • Avoid spreading props blindly ({...props}). Be explicit about what's passed

State Management

  • useState for local UI state, useReducer for complex logic with multiple related values
  • Lift state only as high as needed — avoid prop drilling beyond 2 levels
  • Context for global concerns (theme, auth, locale). Never for frequently updating values
  • Server state belongs in TanStack Query or SWR, not useState/useReducer/Context
  • Derive values from existing state instead of syncing with useEffect
  • URL is state too: use searchParams for filters, pagination, selected tabs
  • Form state: use controlled inputs for validation, uncontrolled (refs) for simple forms

Hooks

  • Follow Rules of Hooks. Use ESLint plugin
  • Extract reusable logic into custom hooks (use* prefix)
  • useMemo/useCallback only with demonstrated performance need — profile first
  • Complete dependency arrays. Never disable exhaustive-deps
  • useEffect is for synchronization with external systems, not for derived state
  • Cleanup functions in useEffect for subscriptions, timers, event listeners
  • Custom hooks should return objects (not arrays) when returning 3+ values

Patterns

  • Composition over configuration: children/render props over config objects
  • Handle loading, error, and empty states in every data component
  • ErrorBoundary at route/feature boundaries, not around individual components
  • React.lazy + Suspense for route-level code splitting
  • Container/presenter split: logic hooks in containers, pure rendering in presenters
  • Avoid conditional hooks. Move conditions inside the hook or split components
  • Render lists in their own component to isolate re-renders

Read the full file on GitHub · 55 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. yesterday First seen · 55 lines · 565 tokens per session scan A 022a2f18c45b

Subscribe to this mod's changes

react is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 5mo ago), licensed MIT. It adds 565 tokens to every session, about $0.0028 per session on Opus 5. A static security scan graded it A with 0 findings. It is 100% identical to react, differing in 0 lines, and is treated as a copy.