Skip to main content

Module: browser

Tools for accessing Convex in the browser.

If you are using React, use the react module instead.

Usage

Create a ConvexHttpClient to connect to the Convex Cloud.

import { ConvexHttpClient } from "convex/browser";
import clientConfig from "../convex/_generated/clientConfig";
const convex = new ConvexHttpClient(clientConfig);

Interfaces

Classes

Type Aliases

GenericAPI

Ƭ GenericAPI: Object

Description of the Convex functions available to an application.

This is a generic type that expresses the shape of API types created by npx convex codegen. It's used to make the Convex clients type-safe.

Type declaration

NameType
queriesRecord<string, (...args: any[]) => any>
mutationsRecord<string, (...args: any[]) => any>

QueryNames

Ƭ QueryNames<API>: keyof API["queries"] & string

The names of query functions in a Convex API.

Type parameters

NameType
APIextends GenericAPI

MutationNames

Ƭ MutationNames<API>: keyof API["mutations"] & string

The names of mutation functions in a Convex API.

Type parameters

NameType
APIextends GenericAPI

NamedQuery

Ƭ NamedQuery<API, Name>: API["queries"][`Name`]

The type of a query function in a Convex API.

Type parameters

NameType
APIextends GenericAPI
Nameextends QueryNames<API>

NamedMutation

Ƭ NamedMutation<API, Name>: API["mutations"][`Name`]

The type of a mutation function in a Convex API.

Type parameters

NameType
APIextends GenericAPI
Nameextends MutationNames<API>

ApiFromModules

Ƭ ApiFromModules<Modules>: Object

Create the API type from the types of all of the modules.

Input is an object mapping file paths to the type of each module.

For internal use by Convex code generation.

Type parameters

NameType
Modulesextends Record<string, Record<string, any>>

Type declaration

NameType
queriesExpand<ConvertToClientFunctions<PickByValue<MergeAllExports<Modules>, { isQuery: true }>>>
mutationsExpand<ConvertToClientFunctions<PickByValue<MergeAllExports<Modules>, { isMutation: true }>>>

ClientOptions

Ƭ ClientOptions: Object

Options for InternalConvexClient.

Type declaration

NameTypeDescription
unsavedChangesWarning?booleanWhether to prompt the user that have unsaved changes pending when navigating away or closing a web page with pending Convex mutations. This is only possible when the window object exists, i.e. in a browser. The default value is true.
webSocketConstructor?typeof WebSocketSpecifies an alternate WebSocket constructor to use for client communication with the Convex cloud. The default behavior is to use WebSocket from the global environment.

OptimisticUpdate

Ƭ OptimisticUpdate<API, Arguments>: (localQueryStore: OptimisticLocalStore<API>, ...args: Arguments) => void

Type parameters

NameType
APIextends GenericAPI
Argumentsextends any[]

Type declaration

▸ (localQueryStore, ...args): void

A temporary, local update to query results within this client.

This update will always be executed when a mutation is synced to the Convex server and rolled back when the mutation completes.

Note that optimistic updates can be called multiple times! If the client loads new data while the mutation is in progress, the update will be replayed again.

Parameters
NameTypeDescription
localQueryStoreOptimisticLocalStore<API>An interface to read and edit local query results.
...argsArgumentsThe arguments to the mutation.
Returns

void


QueryResult

Ƭ QueryResult: { success: true ; value: Value } | { success: false ; errorMessage: string }

The result of running a query function on the server.

If the function hit an exception it will have an errorMessage. Otherwise it will produce a Value.


QueryToken

Ƭ QueryToken: string

A string representing the name and arguments of a query.

This is used by the InternalConvexClient.