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 Parameter | Default type |
|---|---|
R extends Row | - |
Schema extends Readonly<Record<string, Readonly<Record<string, Type<any, any, any, any, any, any>>>>> | - |
MappedRow | R |
Parameters
| Parameter | Type | Description |
|---|---|---|
evolu | Evolu<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) => MappedRow | This is a little helper so that you can map the results instead of using a $derive operation. |
Returns
object
| Name | Type | Defined in |
|---|---|---|
rows | MappedRow[] | index.svelte.ts:73 |