with-react

A set of modern React coding rules for making components easier to read, maintain, and predict. React is a JavaScript library for building user interfaces.

In plain words
What is it for?
Use it when designing React components, deciding what belongs in state, deriving values from existing data, and modeling loading, success, and error states.
Why use it?
It helps prevent duplicated or inconsistent UI state by deriving values when possible and using clearer state transitions for multi-step flows.

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/zackiles/cursor-config/with-react
Clone the repo
git clone --depth 1 https://github.com/zackiles/cursor-config

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 834 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.00834
Opus 5 $0.00000 $0.00417
Sonnet 5 $0.00000 $0.00167
Haiku 4.5 $0.00000 $0.00083

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

Security

Grade A, and why

with-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 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/global/with-react.mdc · 171 lines

How it starts

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

React Code Style Guide

This guide outlines modern React patterns to improve readability, maintainability, and predictability in your components.


1. Treat UIs as Thin Wrappers Over Data

  • Avoid useState for anything that can be derived from props or global state.
  • Use useState only when the value is truly local and reactive.
// Prefer
const isVisible = props.status === 'open'

// Avoid
const [isVisible, setIsVisible] = useState(false)

2. Flatten UI State into Derived Calculations

  • If the UI state can be computed, avoid storing it.
const isFormDisabled = !formData.name || !formData.email

3. Prefer State Machines Over Multiple useStates

  • Use a state machine to model UI flows with clear transitions.
// Pseudo code with a basic state machine model
const [state, transition] = useState<'idle' | 'loading' | 'success' | 'error'>('idle')

function onSubmit() {
  transition('loading')
  sendRequest()
    .then(() => transition('success'))
    .catch(() => transition('error'))
}

return (
  <>
    {state === 'idle' && <Form onSubmit={onSubmit} />}
    {state === 'loading' && <Spinner />}
    {state === 'success' && <SuccessMessage />}
    {state === 'error' && <ErrorMessage />}
  </>
)
// For complex flows, consider XState
const [state, send] = useMachine(myFormMachine)

if (state.matches('loading')) return <Spinner />

4. Extract Logic-Heavy JSX into Components

  • Avoid deeply nested ternaries or conditionals in JSX.
  • Encapsulate logic in dedicated components.
// Prefer
return <UserView user={user} />

// Avoid
return user ? (
  user.isAdmin ? <AdminPanel /> : <UserPanel />
) : (
  <LoadingIndicator />
)

5. Avoid Implicit Logic in useEffect

  • Avoid logic that reacts indirectly via dependencies.
  • Prefer deriving the value directly.
// Prefer
const shouldShowBanner = user.hasSubscription && !user.dismissedBanner

// Avoid
useEffect(() => {
  if (user.hasSubscription && !user.dismissedBanner) {
    showBanner()
  }
}, [user])

Read the full file on GitHub · 171 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 · 171 lines · 834 tokens per session scan A b2408757dd2a

Subscribe to this mod's changes

with-react is a cursor rule published in the GitHub repository zackiles/cursor-config (17 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 834 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.