
State Management
This is a solid reference for combining TanStack Query v5 with Zustand v5 in React apps, covering 26+ patterns from basic data fetching to optimistic updates. The breaking changes section up front is helpful since v5 changed `cacheTime` to `gcTime` and removed `onSuccess` from `useQuery`. I like the query keys factory pattern and the clear separation between server state (React Query) and client state (Zustand). The optimistic update examples with rollback logic are thorough. Most useful when you're setting up data fetching infrastructure or need to sync server cache with local stores. The security note about not persisting auth tokens in localStorage is worth highlighting to your team.
- skills.sh installs
- 834
- GitHub stars
- 102
- last updated
- Aug 21, 2026
Install
$ npx -y skills add asyrafhussin/agent-skills --skill state-management --agent claude-codeInstalls into .claude/skills of the current project.
Files
State Management with React Query + Zustand
Version 1.1.0 | TanStack Query v5 | Zustand v5 | March 2026
Note: This document provides comprehensive patterns for AI agents and LLMs working with TanStack Query v5 and Zustand v5. All examples are verified against v5 APIs. Optimized for automated refactoring, code generation, and state management best practices.
v5 Breaking Changes (Quick Reference)
TanStack Query v5:
cacheTime→gcTimekeepPreviousDataoption →placeholderData: keepPreviousData(imported helper)isPreviousData→isPlaceholderDataonSuccess/onError/onSettledremoved fromuseQuery— still valid onuseMutationsuspense: trueonuseQueryremoved → useuseSuspenseQuery
Zustand v5:
shallowas 2nd arg removed →useShallowfromzustand/shallow- Selectors returning new references need
useShallowto avoid infinite loops
Security: Persist Middleware
Never persist auth tokens, passwords, or secrets to localStorage/sessionStorage. Use
partializeto persist only non-sensitive state. Manage tokens via HttpOnly cookies.
Sponsors
Details
- Repository
- github.com/asyrafhussin/agent-skills
- Categories
- Frontend Development, AI & Agent Building
- First seen
- Jun 3, 2026
More from asyrafhussin/agent-skills
All 14- Php Best Practices3.8K
- React Vite Best Practices3K
- Laravel Best Practices2.4K
- Laravel Inertia React2K
- Clean Code Principles1.9K
- Typescript React Patterns1.1K
- Laravel Database Optimization1.1K
- Laravel Owasp Security1.1K
- Tailwind Best Practices1K
- Api Design Patterns984
- Testing Best Practices957
- Web Design Guidelines948
- Git Workflow890