react-rules

A collection of React coding conventions for building user interfaces, including guidance on component size, state, effects, props, and shared data.

In plain words
What is it for?
It helps structure React components, decide when to use useEffect or useState, move logic into plain TypeScript functions, define props, and manage state with reducers or context.
Why use it?
It aims to reduce complex components, unnecessary state, hard-to-test logic, and unpredictable behavior caused by shared global data.

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/openstory-so/openstory/react-rules
Clone the repo
git clone --depth 1 https://github.com/openstory-so/openstory

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 989 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.00989
Opus 5 $0.00000 $0.00495
Sonnet 5 $0.00000 $0.00198
Haiku 4.5 $0.00000 $0.00099

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

Security

Grade A, and why

react-rules 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 2d 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.

.cursor/rules/react-rules.mdc · 110 lines

How it starts

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

1. Use as little React as possible

  • Keep components small - less than 100 lines
  • Views reference components
  • Remove as much logic as possible from components and views
  • Externalize functions rather and keep external functions vanilla typescript
  • Vanilla typescript is easier to test, and package for other uses

2. Avoid using useEffect

  • Avoid using useEffect to fetch data or initialise state
  • Use hooks, tanstack query, or the new use feature in react 19
  • use useEffect to update state when something else changes

3. Use useState sparingly

  • Using a local variable is often more optimal - even if something has to be calculated
  • useState uses reducers under the hood
  • If you have more than 3 useStates you might as well use reducers

4. Use React.FC and expand props

  • Expand props so that each parameter is named
  • It's easier to know which props are not used

5. Avoid globals and global state

  • Globals including auth globals, often lead to race conditions
  • Global state is only useful in rare cases. SPAs with signifant complexity
  • Start with reducers which are passed through props
  • If that's too complicated, use React context
  • As a last resort for very complicated SPAs - use zustand

6. Use reducers

  • Reducers are great - read up on them and understand them
  • They keep all state update logic in one place
  • They are vanilla typescript - keep them that way
  • Use them to update state based on other state.
  • Note that updating any part of the state returned from a reducer will cause a re-render if the whole state is a parameter - you can pass just parts of it

7. Avoid passing style to components

  • Avoid passing styles to components, or styling your components in views
  • Create components that are pre-styled
  • Create variants - e.g. small, medium, large - rather than size={18}
  • Avoid using styles in views as much as possible

8. Use the theme

  • Create constants for your theme or use a consistent structure
  • Use the theme fonts and colors
  • Avoid naming fonts and inluding color values directly in views and components

Read the full file on GitHub · 110 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. 2d ago First seen · 110 lines · 989 tokens per session scan A 41e965deebf3

Subscribe to this mod's changes

react-rules is a cursor rule published in the GitHub repository openstory-so/openstory (519 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 989 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-30.