UNPKG

react-query-external-sync

Version:

A tool for syncing React Query state to an external Dev Tools

42 lines (41 loc) 1.4 kB
import { QueryClient } from '@tanstack/react-query'; export interface MmkvStorage { getAllKeys(): string[]; getString(key: string): string | undefined; getNumber(key: string): number | undefined; getBoolean(key: string): boolean | undefined; addOnValueChangedListener(listener: (key: string) => void): { remove: () => void; }; } export interface UseDynamicMmkvQueriesOptions { /** * The React Query client instance */ queryClient: QueryClient; /** * The MMKV storage instance to use */ storage: MmkvStorage; } export interface MmkvQueryResult { key: string; data: unknown; isLoading: boolean; error: Error | null; } /** * Hook that creates individual React Query queries for each MMKV key * This gives you granular control and better performance since each key has its own query * Automatically listens for MMKV changes and updates the relevant queries * * @example * // Get individual queries for all MMKV keys * const queries = useDynamicMmkvQueries({ queryClient, storage }); * // Returns: [ * // { key: 'sync_download_progress', data: 75, isLoading: false, error: null }, * // { key: 'user_preference', data: 'dark', isLoading: false, error: null }, * // ... * // ] */ export declare function useDynamicMmkvQueries({ queryClient, storage }: UseDynamicMmkvQueriesOptions): MmkvQueryResult[];