[API reference](https://evolu.dev/docs/api-reference) › [@evolu/svelte](https://evolu.dev/docs/api-reference/svelte) › queryState

```ts
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](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/svelte/src/lib/index.svelte.ts#L56)

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

### Example

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

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

### Example

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