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-code

Installs 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 → gcTime
  • keepPreviousData option → placeholderData: keepPreviousData (imported helper)
  • isPreviousData → isPlaceholderData
  • onSuccess/onError/onSettled removed from useQuery — still valid on useMutation
  • suspense: true on useQuery removed → use useSuspenseQuery

Zustand v5:

  • shallow as 2nd arg removed → useShallow from zustand/shallow
  • Selectors returning new references need useShallow to avoid infinite loops

Security: Persist Middleware

Never persist auth tokens, passwords, or secrets to localStorage/sessionStorage. Use partialize to 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
1bitjaru avatarss-motionbitjaru/styleseedApply a named StyleSeed motion to a component — either one of the 5 personality seeds (Spring/Silk/Snap/Float/Pulse × entrance/exit/hover/press/layout) or a dis832skills.sh installs
2dodopayments avatarbilling-sdkdodopayments/skillsGuide for building billing UI with BillingSDK - the open-source React component library for pricing tables, subscription management, usage meters, invoice histo831skills.sh installs
3softaworks avatarmuisoftaworks/agent-toolkitMaterial-UI v7 component library patterns including sx prop styling, theme integration, responsive design, and MUI-specific hooks. Use when working with MUI com824skills.sh installs
4getstream avatarstream-docsgetstream/agent-skillsSearch live Stream SDK documentation for Chat, Video, Feeds, and Moderation. Look up how a Stream React/iOS/Android/Node/Flutter/Unity/Angular hook, component, 822skills.sh installs
5lobehub avatardata-fetchinglobehub/lobehubData fetching architecture guide using Service layer + Zustand Store + SWR. Use when implementing data fetching, creating services, working with store hooks, or812skills.sh installs
6pproenca avatartypescript-refactorpproenca/dot-skillsTypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should b799skills.sh installs