API reference@evolu/svelte › queryState

function queryState<R, Schema, MappedRow>(
  evolu: Evolu<Schema>,
  observedQuery: () => Query<Schema, R> | undefined,
  options?: {
    mapping?: (row: R) => MappedRow;
  },
): {
  rows: MappedRow[];
};

Defined in: index.svelte.ts:56

Load and subscribe to the Query, and return an object with rows property that are automatically updated when data changes.

Example

// Create your query
const allTodos = evolu.createQuery((db) => db.selectFrom("todo").selectAll());

// Get all rows.
const allTodosState = queryState(evolu, () => allTodos);

Example

// some kind of state
let someKindOfState = $state("someId");

// derive your query based other props
const allTodos = $derived(
  evolu.createQuery((db) =>
    db.selectFrom("todo").where("id", "=", someKindOfState).selectAll(),
  ),
);

// Get all rows, once someKindOfState changes, this allTodosState will be updated with the evolu query result
const allTodosState = queryState(evolu, () => allTodos);

// use allTodosState.rows in further calculations / UI