state-management

state-management is a cursor rule for Cursor from girijashankarj/cursor-handbook. It costs 0 tokens per session (473 once invoked), scanned A, original, MIT.

A set of rules for managing data used by a frontend application. It separates local interface state, shared state, form values, URL filters, and data loaded from APIs.

In plain words
What is it for?
It helps choose patterns for forms, modal state, shared settings, API data, filters, pagination, and selected tabs in React applications.
Why use it?
It prevents application data from being stored or fetched inconsistently. Clear ownership of each kind of state makes interfaces easier to change and debug.

Cursor rule for Cursor

Written for Cursor: installed under .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/girijashankarj/cursor-handbook/state-management
Clone the repo
git clone --depth 1 https://github.com/girijashankarj/cursor-handbook

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 state-management

README.md
[![agentmods](https://agentmods.dev/badge/rules/girijashankarj/cursor-handbook/state-management.svg)](https://agentmods.dev/rules/girijashankarj/cursor-handbook/state-management)
Your own site
<a href="https://agentmods.dev/rules/girijashankarj/cursor-handbook/state-management"><img src="https://agentmods.dev/badge/rules/girijashankarj/cursor-handbook/state-management.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 473 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.1 $0.00000 $0.00473
Opus 5 $0.00000 $0.00236
Sonnet 5 $0.00000 $0.00095
Haiku 4.5 $0.00000 $0.00047

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

Security

Grade A, and why

state-management 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/frontend/state-management.mdc · 59 lines

What it actually says

State Management Rules

State Categories

Category Tool Example
UI State useState / useReducer Modal open, form input, toggle
Shared UI State Context API / Zustand Theme, sidebar, notifications
Server State TanStack Query / SWR API data, user profile, lists
Form State React Hook Form Form values, validation, submission
URL State Router params / search params Filters, pagination, selected tab

Rules

Local State

  • Keep state as close to where it's used as possible
  • Lift state up only when siblings need to share it
  • Use useReducer for complex state with multiple sub-values

Server State

  • Use TanStack Query (React Query) for all API calls
  • Configure stale time and cache time appropriately
  • Use query keys that include all dependencies
  • Implement optimistic updates for better UX
  • Handle loading, error, and empty states explicitly
// CORRECT - Using TanStack Query
const { data, isLoading, error } = useQuery({
  queryKey: ['orders', filters],
  queryFn: () => fetchOrders(filters),
  staleTime: 5 * 60 * 1000, // 5 minutes
});

// WRONG - Manual fetch in useEffect
const [data, setData] = useState(null);
useEffect(() => {
  fetch('/api/orders').then(r => r.json()).then(setData);
}, []);

Global State

  • Keep global state minimal — most state should be local or server
  • Use Zustand for lightweight global state
  • Use Redux Toolkit only if the app has complex client-side state
  • NEVER put server data in global state — use React Query

Performance

  • Avoid unnecessary re-renders by keeping state granular
  • Use selectors for derived state
  • Memoize expensive derived computations
  • Use React.memo for components that receive stable props
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 · 59 lines · 0 tokens per session scan A beb81ef0e1e3

Subscribe to this mod's changes

state-management is a cursor rule published in the GitHub repository girijashankarj/cursor-handbook (30 stars, last pushed 6d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 473 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-09-03.