React Functions
useDB
useDB(): GoatDB<US>
Opens a local DB, creating it if necessary. Once opened, the DB is available as a react context. All future calls return the already opened DB rather than opening it again.
This hook will trigger a re-render whenever the current user changes.
useDBReady
useDBReady(): DBReadyState
A hook for monitoring the DB's loading process. The hook triggers whenever the loading process changes its state.
useItem
useItem(pathComps: string[]): ManagedItem<S, Schema>
This hook monitors changes to a specific item, triggering a re-render whenever the item's state changes. It returns a mutable ManagedItem instance that allows direct editing. Any changes to the item are automatically queued for background commit and synchronization with the server. Similar to the useQuery hook, useItem reacts to both local and remote updates.
useQuery
useQuery(config: UseQueryOpts<IS, CTX, OS>): Query<IS, OS, CTX>
Creates a new query or retrieves an existing one. On first access, GoatDB automatically loads the source repository either from the local disk or by fetching it from the server. The hook triggers UI re-rendering whenever the query results are updated, regardless of whether the changes originate from local or remote edits.
When a query is first opened, it performs a linear scan of its source using a Coroutine without blocking the main thread. During and after this initial scan, the query caches its results to disk, allowing subsequent runs to resume execution from the cached state. For additional details, refer to the mechanism documentation.