Interface · Workflows & Automation· 7 min read
Lightweight state and real-time dashboards: Zustand and TanStack Query
Replacing heavyweight Redux boilerplate with Zustand and TanStack Query. Managing optimistic updates, client-side caching, and responsive data visualization for enterprise CRMs.
Frontend ArchitectureReactZustandTanStack QueryState Management
On this page
Legacy enterprise frontends frequently drown in Redux boilerplate: separate action types, action creators, reducers, and thunks for every single API interaction. In my frontend architectures for the private telecom CRM and multi-tenant portals, state management is cleanly separated into two distinct concerns: Server Cache (managed by TanStack Query) and Client Store (managed by Zustand).
Separating server cache from UI state
| Concern | Owner Tool | Responsibilities |
|---|---|---|
| Server Cache | TanStack Query | Fetching, caching, background refetching, deduping requests, and garbage collection. |
| Client State | Zustand | Sidebar toggle, modal open states, active theme, multi-step draft wizard inputs. |
typescript
import { create } from 'zustand';
interface MarginState {
wholesaleCost: number;
salePrice: number;
quantity: number;
setValues: (vals: Partial<MarginState>) => void;
getProfit: () => number;
}
export const useMarginStore = create<MarginState>((set, get) => ({
wholesaleCost: 0,
salePrice: 0,
quantity: 1,
setValues: (vals) => set((state) => ({ ...state, ...vals })),
getProfit: () => {
const { wholesaleCost, salePrice, quantity } = get();
return (salePrice - wholesaleCost) * quantity;
},
}));