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.
npx agentmods add rules/girijashankarj/cursor-handbook/state-managementgit clone --depth 1 https://github.com/girijashankarj/cursor-handbookWrote 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.
[](https://agentmods.dev/rules/girijashankarj/cursor-handbook/state-management)<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>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.
| Model | Per session | Once 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 |
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.
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
useReducerfor 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.memofor components that receive stable props
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.
- 2d ago First seen · 59 lines · 0 tokens per session scan A beb81ef0e1e3
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.
Other cursor rules, from other repositories
data-fetching
Data fetching patterns with TanStack Query, Server Components, and Supabase.
senior-engineer
Senior-engineer execution defaults for the Next.js + React + Supabase stack — state/data library choices, separation of concerns, security non-negotiables. Attach when building or refactoring features in a React/Next.js/Supabase codebase.
t3-stack
T3 Stack: tRPC + Prisma + NextAuth integration patterns.
nextjs15-supabase-cursorrules-prompt-file
27 architecture rules preventing AI hallucinations: insecure auth (getSession vs getUser), synchronous params, deprecated imports, missing RLS, and Stripe key exposure. Built for Cursor Agent and Claude Code.
python-fastapi-scalable-api-cursorrules-prompt-fil
Cursor rules for Python FastAPI development with scalable API integration.
react-graphql-apollo-client-cursorrules-prompt-file
Cursor rules for GraphQL development with Apollo Client integration.