offline

Keep showing loaded data with no connection, and send queued changes when the network comes back.

Data fetchingClientBuilt onTanStack Query

Every export of kitr/offline, kitr/offline/react, kitr/offline/provider, read from the published type definitions. The guide shows them in use.

kitr/offline

bindOnlineManager

function bindOnlineManager(platform: {
  isOnline(): boolean;
  onOnline(l: (online: boolean) => void): () => void;
}): void;

Let TanStack Query's online state follow the platform driver (native shells report it better than navigator.onLine).

createOffline

function createOffline(client: QueryClient, config?: OfflineConfig, app?: KitrApp): Offline;

useOffline

function useOffline(app: KitrApp): Offline;

defineConfig

const defineConfig: <const C extends OfflineConfig>(config: C) => C;

Offline

interface Offline {
  /** Load a stored snapshot into the client, if fresh. Resolves with whether one was found. */
  restore(): Promise<boolean>;
  /** Write the current cache now (the provider does it on a throttle). */
  persist(): void;
  /** Forget the snapshot. */
  clear(): void;
  /** Mutations waiting for the network. */
  pendingMutations(): number;
  isOnline(): boolean;
  subscribe(listener: () => void): () => void;
  readonly restored: boolean;
}

OfflineConfig

interface OfflineConfig {
  /** Storage key for the cache snapshot. Default `kitr:query-cache`. */
  key?: string;
  /** Milliseconds a snapshot stays usable. Default 24 hours. */
  maxAge?: number;
  /** Persist only queries whose key passes; default: every successful query. */
  include?: (queryKey: QueryKey) => boolean;
  /** Milliseconds to wait after a change before writing. Default 1000. */
  throttle?: number;
  /** Where the snapshot lives. Default: the app's local storage driver (native on desktop/mobile). */
  storage?: StorageDriver;
  /** A string that invalidates old snapshots when the data shape changes (app version). */
  buster?: string;
}

kitr/offline/react

useOffline

function useOffline(): {
  online: boolean;
  pending: number;
  restored: boolean;
  clear: () => void;
  persist: () => void;
};

{ online, pending, restored }: whether the network is up, how many mutations wait for it, and whether the cache came from a stored snapshot. Hydration-safe: the server says online.

kitr/offline/provider

offlineProvider

const offlineProvider: import("@kitr/core").KitrProvider;

Persists the query cache and paused mutations, restores them before the first render and replays the mutations when the network returns (TanStack Query resumes paused mutations on its own once onlineManager says online). Put it after the query provider in kitrrc.ts.