Skip to Content
FrontendState Management

State Management

Client State — Zustand

StoreFileStatePersistence
useUserStorestores/userStore.tsuser, token, isAuthenticatedlocalStorage
useJobStorestores/jobStore.tsJob-related UI state

useUserStore Actions

// Set auth state after login setAuth(user, token) // Clear state on logout logout() // Update wallet address updateWallet(address)

The store persists to localStorage under key fluxpay-user, so sessions survive page refreshes.

Server State — TanStack Query

API data is managed via TanStack Query v5 through custom hooks in hooks/useApi.ts:

  • Automatic caching and background refetching
  • Mutation hooks for create/update operations
  • Query invalidation after mutations

Rule of thumb: Use Zustand for client-only state (auth, UI), TanStack Query for server-fetched data (jobs, profiles, transactions).

Last updated on