Context
The codebase already uses React Query (@tanstack/react-query v5) in 5 hooks (analytics, search, cross-references, etc.), but 13 hooks and most page components still use manual useState/useEffect fetch patterns. This causes duplicate network requests and inconsistent caching.
The most impactful example: projectApi.get() is called independently from 9 different page components — navigating between project pages triggers redundant fetches that React Query's shared cache would eliminate.
Phase 1: useProject hook (completed in PR #86)
Phase 2: Secondary Data Queries (future)
Phase 3: Complex Queries (optional, higher risk)
Not suitable for migration
useSuggestionSession.ts — state machine with strict lifecycle ordering
useAutoSave.ts / useEntityAutoSave.ts — local-first draft management
useTreeDragDrop.ts — optimistic UI with manual rollback
useKeyboardShortcuts.ts, useFilteredTree.ts — UI state, not data fetching
Benefits
- Deduplication — redundant
projectApi.get() calls share a single cache entry
- Stale-while-revalidate — instant page transitions with background refresh
- DevTools — React Query DevTools for debugging query state and cache
- Automatic refetch — on window focus/reconnect
- Simplified error handling — centralized via query error state
Related
Context
The codebase already uses React Query (
@tanstack/react-queryv5) in 5 hooks (analytics, search, cross-references, etc.), but 13 hooks and most page components still use manualuseState/useEffectfetch patterns. This causes duplicate network requests and inconsistent caching.The most impactful example:
projectApi.get()is called independently from 9 different page components — navigating between project pages triggers redundant fetches that React Query's shared cache would eliminate.Phase 1: useProject hook (completed in PR #86)
useProject(projectId)hook wrappingprojectApi.get()inuseQueryderivePermissions()helper to centralize permission logicuseProjectViewer(6 of 9 call sites)invalidateQueriescalls after project mutations in settings pagePhase 2: Secondary Data Queries (future)
useRemoteSync.tstouseQuery+refetchIntervalfor pollinguseProjectViewerinto standaloneuseQueryhooksprojectOntologyApisearchesPhase 3: Complex Queries (optional, higher risk)
useOntologyTree.tsto use React Query with per-node queriesuseGraphData.tsto coordinate multiple queriesinvalidateQueriesstrategy for entity create/update/delete mutationsNot suitable for migration
useSuggestionSession.ts— state machine with strict lifecycle orderinguseAutoSave.ts/useEntityAutoSave.ts— local-first draft managementuseTreeDragDrop.ts— optimistic UI with manual rollbackuseKeyboardShortcuts.ts,useFilteredTree.ts— UI state, not data fetchingBenefits
projectApi.get()calls share a single cache entryRelated