state-management
Skill1 starsChanged 9 months agoMITView on GitHub
Designs client-side state architecture - what lives where, how it syncs with the server, how conflicts resolve, and how to avoid common pitfalls. Use when designing state for web or mobile apps, debugging state issues, or choosing state management patterns.
18 other projects use a version of this.
Adopted by
Most recently taken up by
- brianshepardpss/analyzer-looptheir own version, first seen Oct 2, 2026
- compozy/compozytheir own version, first seen Oct 1, 2026
- komluk/scaffoldingtheir own version, first seen Sep 28, 2026
- alfredobs97/flutter_agentic_templatetheir own version, first seen Sep 24, 2026
- novatic-cu/nova-skillstheir own version, first seen Sep 20, 2026
- LeonxLJX/web-engineer-skillstheir own version, first seen Sep 3, 2026
Used with
Projects with it also use css-architecture.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
Piyush8296Skillcss-architecture
CSS architecture, Tailwind patterns, responsive design, design tokens, and styling best practices. Use when implementing designs, setting up styling infrastructure, or debugging layout issues.
Also in 3 projects that use this
Other versions18 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 18
- compozy/compozy★ 2.8ksame name
- conorluddy/xclaude-plugin★ 182same name
- Owl-Listener/ai-design-skills★ 178same name
- cohen-liel/hivemind★ 110same name
- TheBeardedBearSAS/claude-craft★ 106same name
- statelyai/skills★ 48same name
- komluk/scaffolding★ 15same name
- autohandai/community-skills★ 11same name
- PMDevSolutions/Aurelius★ 8same name
- YepAPI/skills★ 8same name
8 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository48 other files it gives its agents.
- accessibilitySkill
- api-designSkill
- api-integrationSkill
- architectSkill
- async-patternsSkill
- best-practicesSkill
- bugSkill
- buildSkill
- cachingSkill
- ci-cdSkill
- config-managementSkill
- containerizeSkill
- database-designSkill
- data-modelingSkill
- data-pipelineSkill
- debug-latencySkill
- dependency-updateSkill
- deploySkill
- dev-setupSkill
- docsSkill
- error-handlingSkill
- estimateSkill
- feature-flag-opsSkill
- git-recoverySkill
- i18nSkill
- iacSkill
- incidentSkill
- load-testingSkill
- loggingSkill
- migrateSkill
- monitoringSkill
- observability-debugSkill
- onboardSkill
- perfSkill
- phase-gateSkill
- pr-authorSkill
- qaSkill
- refactorSkill
- reviewSkill
- rollbackSkill
- schema-evolutionSkill
- scope-checkSkill
- security-auditSkill
- tech-debtSkill
- tech-stackSkill
- telemetrySkill
- testingSkill
- workflowSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 4 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Every UI bug is a state bug.
- Distinctive: line 51
Cache invalidation: When does cached data become stale?
- Distinctive: line 110
Lift state up ONLY when a sibling component needs it: Don't prematurely globalize.
- Distinctive: line 118
Search queries and filters
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
State Management
Every UI bug is a state bug. The component rendered the wrong thing because it had the wrong data. The question is always: where should this state live, and how does it stay correct?
Reference:
reference/state-patterns.md- State location decision tree, framework comparison, derived state, optimistic updates, state machines, common bugs.
Where State Lives
The Decision Matrix
| Question | If YES → | If NO → |
| Does the server own this data? | Server state | Client state |
| Does it persist across page refreshes? | Server or URL state | Component state |
| Is it shared across multiple components? | Global/shared state | Local component state |
| Should it be bookmarkable/shareable? | URL state | Not URL state |
State Types
| Type | Where | Examples | Tool |
| Server state | Database, API | User profile, orders, products | React Query, SWR, Apollo, RTK Query |
| URL state | Browser URL | Current page, filters, search query, sort order | Router, URLSearchParams |
| Global UI state | Memory (store) | Auth status, theme, sidebar open/closed | Zustand, Redux, Jotai, Context |
| Local UI state | Component | Input value, dropdown open, hover state | useState, local state |
| Form state | Component/library | Field values, validation, dirty/touched | React Hook Form, Formik |
| Derived state | Computed | Filtered list, totals, formatted values | Computed/memo, selectors |
The #1 mistake: Putting server state in a global store (Redux, Zustand) and manually keeping it in sync. Use a server state library instead.
Server State
Data that lives on the server and is fetched/cached/synced by the client.
The Pattern
Component needs data
→ Check cache (is it fresh?)
→ YES: render from cache (instant)
→ NO: fetch from server, update cache, render
→ In background: revalidate stale dataKey Concepts
Cache invalidation: When does cached data become stale?
- Time-based: "refetch after 5 minutes" (staleTime)
- Event-based: "refetch after mutation" (invalidate on write)
- Focus-based: "refetch when user returns to tab" (window focus)
Optimistic updates: Show the expected result immediately, rollback if server rejects.
User clicks "Like"
→ Immediately show liked state (optimistic)
→ Send request to server
→ Success: done (UI already correct)
→ Failure: rollback to previous state, show errorStale-while-revalidate: Show cached (possibly stale) data instantly while fetching fresh data in the background.
Global UI State
State shared across components that doesn't come from the server.
Keep It Small
Most state people put in global stores should be:
- Server state → Use React Query / SWR (not Redux)
- URL state → Use the router (not Redux)
- Local state → Use component state (not Redux)
What actually belongs in a global store:
- Auth state (logged in user, token)
- Theme / appearance preferences
- UI mode (sidebar expanded, notification panel open)
- Feature flags (if client-evaluated)
State Shape
// GOOD: Normalized, flat, minimal
{
auth: { userId: "123", token: "abc" },
ui: { sidebarOpen: false, theme: "dark" }
}
// BAD: Nested, duplicated, over-stored
{
currentUser: { id: "123", name: "Alice", orders: [...], profile: {...} },
selectedOrder: { ...duplicate of data already in currentUser.orders },
filteredOrders: [...derived data that should be computed, not stored]
}Local Component State
State that belongs to a single component and doesn't need to be shared.
Use local state for:
- Input field values (before form submission)
- Toggle states (dropdown open, accordion expanded)
- Hover/focus states
- Animation state
- Temporary UI state (loading spinners, error messages)
Lift state up ONLY when a sibling component needs it. Don't prematurely globalize.
URL State
The URL is state. Treat it as such.
Put in the URL:
- Current page/route
- Search queries and filters
- Sort order
- Pagination (page number)
- Selected tab
- Modal open with ID (
/users?edit=123)
Why: Bookmarkable, shareable, browser back button works, survives refresh.
Don't put in the URL:
- Transient UI state (hover, focus)
- Large objects or sensitive data
- State that changes every keystroke (debounce search → URL)
Derived State
State that can be computed from other state. Never store derived state. Compute it.
// BAD: Storing derived state
const [items, setItems] = useState([...]);
const [filteredItems, setFilteredItems] = useState([...]);
// Now you must keep filteredItems in sync with items AND filter criteria
// GOOD: Computing derived state
const [items, setItems] = useState([...]);
const [filter, setFilter] = useState('');
const filteredItems = useMemo(
() => items.filter(item => item.name.includes(filter)),
[items, filter]
);Common Bugs and Fixes
| Bug | Cause | Fix |
| Stale data after mutation | Cache not invalidated | Invalidate/refetch after mutations |
| UI flickers on navigation | Showing loading state for cached data | Stale-while-revalidate, keep previous data |
| State lost on refresh | State in memory, not URL or server | Put persistent state in URL or server |
| Components out of sync | Same data copied in multiple places | Single source of truth, derived state |
| Infinite re-render loop | State update in render, missing deps | Fix dependency arrays, move effects |
| Race condition on fetch | Slow request returns after fast one | Cancel previous request, use latest |
| Zombie child updates | Async callback updates unmounted component | Cleanup in effect, use abort controller |
Anti-Patterns
| Anti-Pattern | Problem | Fix |
| Everything in Redux/global store | Unnecessary complexity, over-rendering | Match state type to the right location |
| Manual server state sync | Stale data, complex update logic | Use server state library (React Query, SWR) |
| Storing derived state | Out of sync, extra update logic | Compute with useMemo / selectors |
| Prop drilling 8 levels deep | Fragile, hard to refactor | Context for widely-shared state, composition for component trees |
| Premature global state | Components coupled to store shape | Start local, lift up only when needed |
| Mutable state updates | Subtle bugs, stale closures, no re-render | Immutable updates (spread, immer) |
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.

