cursor-handbook / frontend
Cursor rule31 starsChanged 3 months agoMITView on GitHub
Frontend state management patterns and best practices. Apply when managing client state.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository30 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/architecture/core-principles.mdcCursor rule
- .cursor/rules/architecture/dependency-management.mdcCursor rule
- .cursor/rules/architecture/token-efficiency.mdcCursor rule
- .cursor/rules/backend/api-design.mdcCursor rule
- .cursor/rules/backend/code-organization.mdcCursor rule
- .cursor/rules/backend/error-handling.mdcCursor rule
- .cursor/rules/backend/handler-patterns.mdcCursor rule
- .cursor/rules/backend/nodejs.mdcCursor rule
- .cursor/rules/backend/typescript.mdcCursor rule
- .cursor/rules/cloud/containerization.mdcCursor rule
- .cursor/rules/cloud/infrastructure.mdcCursor rule
- .cursor/rules/cloud/serverless.mdcCursor rule
- .cursor/rules/database/migration-rules.mdcCursor rule
- .cursor/rules/database/query-patterns.mdcCursor rule
- .cursor/rules/database/schema-design.mdcCursor rule
- .cursor/rules/devops/ci-cd.mdcCursor rule
- .cursor/rules/devops/documentation-standards.mdcCursor rule
- .cursor/rules/devops/monitoring.mdcCursor rule
- .cursor/rules/frontend/accessibility.mdcCursor rule
- .cursor/rules/frontend/component-patterns.mdcCursor rule
- .cursor/rules/frontend/performance.mdcCursor rule
- .cursor/rules/main-rules.mdcCursor rule
- .cursor/rules/security/guardrails.mdcCursor rule
- .cursor/rules/security/secrets-rules.mdcCursor rule
- .cursor/rules/security/security-compliance.mdcCursor rule
- .cursor/rules/testing/integration-testing.mdcCursor rule
- .cursor/rules/testing/mock-patterns.mdcCursor rule
- .cursor/rules/testing/testing-standards.mdcCursor rule
The file
We split this state-management.mdc into the rules it gives an agent
11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Keep state as close to where it's used as possible
- Very specific: line 24
Use useReducer for complex state with multiple sub-values
- Distinctive: line 27
Use TanStack Query (React Query) for all API calls
- Distinctive: line 29
Use query keys that include all dependencies
- Distinctive: line 49
Keep global state minimal — most state should be local or server
- Distinctive: line 50
Use Zustand for lightweight global state
- Distinctive: line 51
Use Redux Toolkit only if the app has complex client-side state
- Distinctive: line 52
NEVER: put server data in global state — use React Query
- Distinctive: line 55
Avoid unnecessary re-renders by keeping state granular
- Distinctive: line 56
Use selectors for derived state
- Very specific: line 58
Use React.memo for components that receive stable props
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Frontend state management patterns and best practices. Apply when managing client state."
alwaysApply: false
globs: "**/*.tsx,**/*.jsx,**/store/**/*,**/state/**/*"
---
# 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
```tsx
// 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
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

