zustand-state
Skill1 starsChanged 5 months agoMITView on GitHub
Client-only UI state stores with Zustand for Next.js 16 App Router and React 19 — a small typed create() store, persist middleware with partialize to save only IDs and UI prefs (never fetched server objects), and an isHydrated/skipHydration guard to avoid SSR hydration mismatches. Use when adding a Zustand store, persisting a sidebar/theme/filter/selection to localStorage, fixing a "Text content did not match" or hydration warning from a persisted store, or deciding what belongs in client state versus server cache. Not for server data fetching, caching, or mutations (see react-query) or route/layout/module wiring (see nextjs-module).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- peakdong68/my-skillstheir own version, first seen Aug 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- peakdong68/my-skills★ 0same name
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 repository49 other files it gives its agents.
- accessibilitySkill
- ai-evalsSkill
- ai-integrationSkill
- architecture-decisionsSkill
- audit-loggingSkill
- aws-servicesSkill
- browser-e2e-testingSkill
- celery-tasksSkill
- changelogSkill
- ci-cdSkill
- codebase-guideSkill
- code-reviewSkill
- commit-messageSkill
- cookie-auth-csrfSkill
- dashboard-data-designSkill
- db-concurrencySkill
- debugSkill
- dependency-auditSkill
- deploy-awsSkill
- design-systemSkill
- drf-apiSkill
- drf-zod-contractSkill
- frontend-perfSkill
- git-workflowSkill
- i18n-rtlSkill
- incident-responseSkill
- migrationsSkill
- money-decimalSkill
- multi-tenancySkill
- nextjs-moduleSkill
- observabilitySkill
- perf-reviewSkill
- production-readinessSkill
- product-ux-designSkill
- rbac-permissionsSkill
- react-querySkill
- security-reviewSkill
- skill-authoringSkill
- tailwind-shadcnSkill
- tenant-session-switchSkill
- threat-modelingSkill
- verifySkill
- version-checkSkill
- visual-ui-designSkill
- webhook-handlerSkill
- websockets-channelsSkill
- write-testsSkill
- zod-formsSkill
- example-skillSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
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
- Very specific: line 16
Zustand holds UI state; React Query holds server state: Never mirror fetched objects into a store — cache them with react-query and keep …
- Very specific: line 20
Persist is opt-in and narrow: Use persist + partialize to save only the UI prefs/ids you actually want across reloads, and guard hydration …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill 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
Zustand state (client UI state, not server data)
When to use
You need ephemeral, client-owned UI state that outlives a single component: theme, sidebar open/closed, a wizard step, active filters, or the id of a selected row. If the value comes from the API, it does not belong here.
Pattern
Two rules, held everywhere:
- Zustand holds UI state; React Query holds server state. Never mirror
fetched objects into a store — cache them with
react-queryand keep only references (ids, selection, prefs) in Zustand. Duplicated server data goes stale and desyncs. - Persist is opt-in and narrow. Use
persist+partializeto save only the UI prefs/ids you actually want across reloads, and guard hydration so the server-rendered HTML matches the first client render.
Steps / idioms
A small, typed store — state plus the actions that mutate it, colocated. Persist narrowly with
partialize, and note the hydration hooks used below:// stores/ui.ts import { create } from "zustand"; import { persist, createJSONStorage } from "zustand/middleware"; type UIState = { sidebarOpen: boolean; activeEntrepriseId: string | null; // an id/reference, NOT the fetched object toggleSidebar: () => void; setEntreprise: (id: string | null) => void; }; // create<T>()(...) — the extra () is required for TS inference with middleware export const useUI = create<UIState>()( persist( (set) => ({ sidebarOpen: true, activeEntrepriseId: null, toggleSidebar: () => set((s) => ({ sidebarOpen: !s.sidebarOpen })), setEntreprise: (id) => set({ activeEntrepriseId: id }), }), { name: "ui", // unique per store, avoids localStorage key collisions storage: createJSONStorage(() => localStorage), // persist ONLY prefs + ids; never fetched server lists/objects partialize: (s) => ({ sidebarOpen: s.sidebarOpen, activeEntrepriseId: s.activeEntrepriseId, }), }, ), );- Guard hydration so SSR and the first client paint agree. Track a
hydratedflag withuseState/useEffect— seed it fromuseUI.persist.hasHydrated()and subscribe viauseUI.persist.onFinishHydration(() => …)(it returns an unsubscribe). Render a neutral default untilhydratedis true, then readuseUI(...); this prevents the "Text content did not match" warning. - Select narrow slices (
useUI((s) => s.sidebarOpen)), not the whole store, so components re-render only on the fields they read.
Variants
- Manual rehydration. Set
skipHydration: truein the persist options and calluseUI.persist.rehydrate()yourself (e.g. after reading a cookie or the server-known tenant), instead of the automatic-on-mount default. - Non-persisted store. Drop the
persistwrapper entirely for pure in-memory UI state (a modal, a drag position) — no hydration guard needed.
Adapt to your repo
Rename activeEntrepriseId and the store to your domain, and set a unique
persist name per store to avoid localStorage key collisions. Confirm the
store file is client-side (imported only from "use client" components).
Bump the persist version and add a migrate fn when you change persisted
shape. If you also use Zustand outside Next.js, the hydration guard is only
needed where SSR renders the component.
Gotchas
- Persisting fetched server objects is the classic bug — they go stale and
fight
react-query; persist ids/prefs only viapartialize. - Reading persisted state during the first render without the hydration guard causes "Text content did not match" / hydration-mismatch warnings.
create<T>()(...)needs the extra call parens (curried form) for correct TypeScript inference with middleware — a common copy error.- One module-level store is shared across all users in the same tab; never put per-request secrets or another tenant's data in it.
See also
react-querynextjs-module
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.

