Skip to main content

React Query in MUZE

The frontend uses TanStack React Query v5 for all server state management. This replaces traditional Redux/Zustand patterns for API data.

Provider setup

The provider wraps the app in App.tsx together with SessionProvider and the toast mount point.

Cache tiers (Phase 2.12)

Cached data is the default render path. Tier constants live in frontend/src/lib/cache-tiers.ts and are shared by pages, the warm-start prefetcher and the sidebar hover prefetch: Changes to reference/directory data are surfaced by the invalidation helpers in lib/query-invalidation.ts; operational queries opt back into refetchOnMount: true. Client-scoped admin and manager queries include activeClientId in the key and guard with enabled: !!activeClientId, so they fire only after the active client resolves. Client-sensitive queries do not use keepPreviousData; a client switch clears the old rows while fresh data loads. Prefetch keys for the login warm-start and the sidebar hover/focus prefetch come from the single lib/navigation-prefetch.ts registry, aligned exactly to the page keys. Sign-out cancels and clears the query cache before navigating to /login. Full policy: doc/architecture_and_workflow.md §10.6.

Query patterns

Fetching data

Creating data

Updating data

Cache invalidation strategy

Query key conventions

Error handling

React Query errors are handled at the component level:

Optimistic updates

For critical UI responsiveness, some mutations use optimistic updates:

What React Query does not manage