Skip to content

Query Hooks

Query hooks live in use-<entity>-query.ts and provide read-only live query access to entity data via PowerSync and TanStack DB.

Use the query barrels for normal app consumption:

import { useWorkProjects } from "@life-manager/db/hooks/queries/work";
import { useSingleCashflows } from "@life-manager/db/hooks/queries/finance";
import { useSettings } from "@life-manager/db/hooks/queries/system";

Entity subpaths also export their local query hooks:

import { useWorkProjects } from "@life-manager/db/entities/work/project";
  • live and reactive
  • offline-first
  • read-only
  • strongly typed
  • often the source used by action hooks to build guard input

Query hooks are the read side of the architecture.

They should not:

  • perform writes
  • resolve workflows
  • own business-rule decisions

They should:

  • expose current entity state
  • expose derived joined views when needed
  • give action hooks the live state required to build operation input

Current query hooks mostly follow the use<EntityPlural> pattern, for example:

  • useWorkProjects
  • useWorkTimeEntries
  • useRecurringCashflows
  • useSettings
  • useProfileByUserId