veza/apps/web/src/utils/queryClientSingleton.ts

28 lines
735 B
TypeScript
Raw Normal View History

/**
* QueryClient Singleton
* Action 4.6.1.5: Provide global access to QueryClient for state invalidation
*
* This singleton allows stateInvalidation to access QueryClient without
* needing to be inside a React component.
*/
import type { QueryClient } from '@tanstack/react-query';
let queryClientInstance: QueryClient | null = null;
/**
* Set the QueryClient instance
* Should be called once in main.tsx after creating the QueryClient
*/
export function setQueryClient(client: QueryClient): void {
queryClientInstance = client;
}
/**
* Get the QueryClient instance
* Returns null if not set (should not happen in production)
*/
export function getQueryClient(): QueryClient | null {
return queryClientInstance;
}