Skip to main content

Interface: OptimisticLocalStore<API>

browser.OptimisticLocalStore

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

Type parameters

NameType
APIextends GenericAPI = GenericAPI

Methods

getQuery

getQuery<Name>(name, args): undefined | ReturnType<NamedQuery<API, Name>>

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
Nameextends string

Parameters

NameTypeDescription
nameNameThe name of the query.
argsParameters<NamedQuery<API, Name>>An array of the arguments for this query.

Returns

undefined | ReturnType<NamedQuery<API, Name>>

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


setQuery

setQuery<Name>(name, 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
Nameextends string

Parameters

NameTypeDescription
nameNameThe name of the query.
argsParameters<NamedQuery<API, Name>>An array of the arguments for this query.
valueundefined | ReturnType<NamedQuery<API, Name>>The new value to set the query to or undefined to remove it from the client.

Returns

void