Skip to main content

Interface: OptimisticLocalStore

browser.OptimisticLocalStore

A view of the query results currently in the Convex client for use within optimistic updates.

Methods

getQuery

getQuery<Query>(query, ...args): undefined | FunctionReturnType<Query>

Retrieve the result of a query from the client.

Important: Query results should be treated as immutable! Always make new copies of structures within query results to avoid corrupting data within the client.

Type parameters

NameType
Queryextends FunctionReference<"query">

Parameters

NameTypeDescription
queryQueryA FunctionReference for the query to get.
...argsOptionalRestArgs<Query>The arguments object for this query.

Returns

undefined | FunctionReturnType<Query>

The query result or undefined if the query is not currently in the client.

Defined in

browser/sync/optimistic_updates.ts:28


getAllQueries

getAllQueries<Query>(query): { args: FunctionArgs<Query> ; value: undefined | FunctionReturnType<Query> }[]

Retrieve the results are arguments of all queries with a given name.

This is useful for complex optimistic updates that need to inspect and update many query results (for example updating a paginated list).

Important: Query results should be treated as immutable! Always make new copies of structures within query results to avoid corrupting data within the client.

Type parameters

NameType
Queryextends FunctionReference<"query">

Parameters

NameTypeDescription
queryQueryA FunctionReference for the query to get.

Returns

{ args: FunctionArgs<Query> ; value: undefined | FunctionReturnType<Query> }[]

An array of objects, one for each query of the given name. Each object includes:

  • args - The arguments object for the query.
  • value The query result or undefined if the query is loading.

Defined in

browser/sync/optimistic_updates.ts:49


setQuery

setQuery<Query>(query, args, value): void

Optimistically update the result of a query.

This can either be a new value (perhaps derived from the old value from getQuery) or undefined to remove the query. Removing a query is useful to create loading states while Convex recomputes the query results.

Type parameters

NameType
Queryextends FunctionReference<"query">

Parameters

NameTypeDescription
queryQueryA FunctionReference for the query to set.
argsFunctionArgs<Query>The arguments object for this query.
valueundefined | FunctionReturnType<Query>The new value to set the query to or undefined to remove it from the client.

Returns

void

Defined in

browser/sync/optimistic_updates.ts:69