API reference / @evolu/svelte / index.svelte / queryState

Function: queryState()

function queryState<R, Schema, MappedRow>(
  evolu,
  observedQuery,
  options?,
): object;

Defined in: index.svelte.ts:51

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) => ...);

// 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) => use someKindOfState here ));

// 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

Type Parameters

Type ParameterDefault type
R extends Row-
Schema extends Readonly<Record<string, Readonly<Record<string, Type<any, any, any, any, any, any>>>>>-
MappedRowR

Parameters

ParameterTypeDescription
evoluEvolu<Schema>-
observedQuery() => | undefined | Query<R>Can be a normal query or a derived query. Svelte reactivity: it needs to be a callback, if the query is $derived this will re-trigger the load/subscription based on the new query.
options?{ mapping?: (row) => MappedRow; }-
options.mapping?(row) => MappedRowThis is a little helper so that you can map the results instead of using a $derive operation.

Returns

object

NameTypeDefined in
rowsMappedRow[]index.svelte.ts:73

Was this page helpful?