Documentation Index
Fetch the complete documentation index at: https://mintlify.com/get-convex/convex-react-query/llms.txt
Use this file to discover all available pages before exploring further.
ConvexQueryClient subscribes to events from a TanStack Query QueryClient and populates query results for all Convex query function subscriptions. It manages WebSocket subscriptions through the Convex client and keeps TanStack Query’s cache up to date with pushed updates.
Constructor
A
ConvexReactClient instance, or a Convex deployment URL string. When a URL string is provided, a ConvexReactClient is created automatically using the options passed.When
client is a ConvexReactClient, accepts ConvexQueryClientOnlyOptions. When client is a URL string, accepts ConvexQueryClientOptions (which extends ConvexQueryClientOnlyOptions with ConvexReactClientOptions).ConvexQueryClientOnlyOptions
Pass a
QueryClient to connect immediately. This is an alternative to calling .connect() after construction. If omitted, you must call .connect(queryClient) before using the client.A custom fetch implementation for server-side HTTP requests. Take care to avoid bundling this implementation on the client. In TanStack Start, use
createServerOnlyFn for this purpose.Opt out of consistent SSR queries. When
false (the default), consistent mode uses two round trips to ensure all queries share the same database snapshot. Set to true for faster SSR at the cost of potential inter-query inconsistency — for example, a favChannelIds query might reference a channel ID that is absent from a simultaneously fetched channels query.ConvexQueryClientOptions
ConvexQueryClientOptions extends both ConvexQueryClientOnlyOptions and ConvexReactClientOptions. It is used when passing a URL string as the client argument, allowing you to configure both the underlying ConvexReactClient and the ConvexQueryClient in one options object.
Methods
connect
ConvexQueryClient to a TanStack QueryClient. Must be called exactly once, unless a queryClient was passed in the constructor options. Starts listening to QueryCache events to manage Convex subscriptions.
The TanStack Query
QueryClient to connect to.queryFn
queryFn that handles convexQuery and convexAction query keys. Pass the result as the global queryFn in your QueryClient default options.
On the server, queries are executed via HTTP (ConvexHttpClient). On the client, they run via the WebSocket connection and the result is returned from the local cache once available.
Optional fallback
QueryFunction for non-Convex query keys. Defaults to a function that throws an error for unrecognized keys.hashFn
queryKeyHashFn for TanStack Query that correctly serializes Convex FunctionReference objects using getFunctionName() and convexToJson(). Pass the result as the global queryKeyHashFn in your QueryClient default options.
Optional fallback hash function for non-Convex query keys. Defaults to
hashKey from @tanstack/react-query.queryOptions
useQuery or useSuspenseQuery. Unlike convexQuery(), this method embeds the queryFn directly in the returned options object, so it does not require the global default queryFn to be set on the QueryClient.
The Convex query function reference, imported from
convex/_generated/api.The arguments to pass to the query function.
Because TanStack Query does not support per-query
queryKeyHashFn overrides, you must still set queryKeyHashFn: convexQueryClient.hashFn() globally on the QueryClient when using queryOptions.Properties
The underlying
ConvexReactClient instance used for WebSocket subscriptions and queries.Internal map of active Convex subscriptions, keyed by the TanStack Query hash of the query key. Each entry holds the
Watch object and its unsubscribe function. Do not modify this directly.Setup example
queryClient directly in the options to skip the manual connect call:
The
queryKeyHashFn and queryFn are configured on the QueryClient, not on ConvexQueryClient. Always set them in QueryClient’s defaultOptions.queries.