Interface UseQueryReturn<T>

The return value of useQuery.

interface UseQueryReturn<T> {
    ditto: Ditto;
    error: unknown;
    isLoading: boolean;
    items: QueryResultItem<T>[];
    reset: (() => Promise<void>);
    storeObserver?: StoreObserver;
    syncSubscription?: SyncSubscription;
}

Type Parameters

  • T

    The type of query result items.

Properties

ditto: Ditto

The Ditto instance used by this hook. null until the provider has loaded an instance for the requested persistence directory.

error: unknown

The most recent error that occurred while setting up the query.

Use the onError callback parameter to handle errors as they occur.

isLoading: boolean

true during the initial setup of the query. Resetting the query with reset will not set this back to true to avoid flickering when used in UIs.

items: QueryResultItem<T>[]

The items returned by the query.

An empty array while isLoading is true.

reset: (() => Promise<void>)

Reset the state of this hook.

This will cancel and reconfigure the StoreObserver and SyncSubscription, and return error and items to their initial null state.

This does not set isLoading to true during the reset process. However, the promise returned by this function will resolve once the reset is complete.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

storeObserver?: StoreObserver

The underlying Ditto StoreObserver. undefined until the query has been configured.

syncSubscription?: SyncSubscription

The underlying Ditto SyncSubscription. This is undefined when the localOnly parameter is set to true.