Class: ConvexReactClient
react.ConvexReactClient
A Convex client for use within React.
This loads reactive queries and executes mutations over a WebSocket.
Constructors
constructor
• new ConvexReactClient(address
, options?
)
Parameters
Name | Type | Description |
---|---|---|
address | string | The url of your Convex deployment, often provided by an environment variable. E.g. https://small-mouse-123.convex.cloud . |
options? | ConvexReactClientOptions | See ConvexReactClientOptions for a full description. |
Defined in
Accessors
logger
• get
logger(): Logger
Get the logger for this client.
Returns
Logger
The Logger for this client.
Defined in
Methods
setAuth
▸ setAuth(fetchToken
, onChange?
): void
Set the authentication token to be used for subsequent queries and mutations.
fetchToken
will be called automatically again if a token expires.
fetchToken
should return null
if the token cannot be retrieved, for example
when the user's rights were permanently revoked.
Parameters
Name | Type | Description |
---|---|---|
fetchToken | AuthTokenFetcher | an async function returning the JWT-encoded OpenID Connect Identity Token |
onChange? | (isAuthenticated : boolean ) => void | a callback that will be called when the authentication status changes |
Returns
void
Defined in
clearAuth
▸ clearAuth(): void
Clear the current authentication token if set.
Returns
void
Defined in
watchQuery
▸ watchQuery<Query
>(query
, ...argsAndOptions
): Watch
<FunctionReturnType
<Query
>>
Construct a new Watch on a Convex query function.
Most application code should not call this method directly. Instead use the useQuery hook.
Type parameters
Name | Type |
---|---|
Query | extends FunctionReference <"query" > |
Parameters
Name | Type | Description |
---|---|---|
query | Query | A FunctionReference for the public query to run. |
...argsAndOptions | ArgsAndOptions <Query , WatchQueryOptions > | - |
Returns
Watch
<FunctionReturnType
<Query
>>
The Watch object.
Defined in
mutation
▸ mutation<Mutation
>(mutation
, ...argsAndOptions
): Promise
<FunctionReturnType
<Mutation
>>
Execute a mutation function.
Type parameters
Name | Type |
---|---|
Mutation | extends FunctionReference <"mutation" > |
Parameters
Name | Type | Description |
---|---|---|
mutation | Mutation | A FunctionReference for the public mutation to run. |
...argsAndOptions | ArgsAndOptions <Mutation , MutationOptions <FunctionArgs <Mutation >>> | - |
Returns
Promise
<FunctionReturnType
<Mutation
>>
A promise of the mutation's result.
Defined in
action
▸ action<Action
>(action
, ...args
): Promise
<FunctionReturnType
<Action
>>
Execute an action function.
Type parameters
Name | Type |
---|---|
Action | extends FunctionReference <"action" > |
Parameters
Name | Type | Description |
---|---|---|
action | Action | A FunctionReference for the public action to run. |
...args | OptionalRestArgs <Action > | An arguments object for the action. If this is omitted, the arguments will be {} . |
Returns
Promise
<FunctionReturnType
<Action
>>
A promise of the action's result.
Defined in
query
▸ query<Query
>(query
, ...args
): Promise
<FunctionReturnType
<Query
>>
Fetch a query result once.
Most application code should subscribe to queries instead, using the useQuery hook.
Type parameters
Name | Type |
---|---|
Query | extends FunctionReference <"query" > |
Parameters
Name | Type | Description |
---|---|---|
query | Query | A FunctionReference for the public query to run. |
...args | OptionalRestArgs <Query > | An arguments object for the query. If this is omitted, the arguments will be {} . |
Returns
Promise
<FunctionReturnType
<Query
>>
A promise of the query's result.
Defined in
connectionState
▸ connectionState(): ConnectionState
Get the current ConnectionState between the client and the Convex backend.
Returns
The ConnectionState with the Convex backend.
Defined in
close
▸ close(): Promise
<void
>
Close any network handles associated with this client and stop all subscriptions.
Call this method when you're done with a ConvexReactClient to dispose of its sockets and resources.
Returns
Promise
<void
>
A Promise
fulfilled when the connection has been completely closed.