This version (v0.7) has not been published to npm yet.
Skip to content

Reference / @getenginex/sdk-vue / useRealtimeSync

useRealtimeSync() ​

useRealtimeSync(options?): void

Connects realtime to the TanStack Query cache (opt-in). Subscribes to coreTopics.balance() and coreTopics.notification() while there is a user in the session:

  • on balance_update, invalidates the current user's balance query (wallet.getBalance); it never writes to the cache with setQueryData, because the message is incomplete. The query refetches the balance over HTTP;
  • on each notification, invalidates the user's notifications queries;
  • on a topic's onResync (after a reconnection), invalidates what it feeds: wallet (balance) or notifications (notification).

Product topics come in through options.topics; the list and the function form of invalidate always come from the latest options (the options can be a ref or a getter). On the server (SSR) it subscribes to nothing.

Parameters ​

options? ​

MaybeRefOrGetter<RealtimeSyncOptions> = {}

Extra topics.

Returns ​

void

Throws ​

If called in an app without the EnginexPlugin.

Example ​

ts
useRealtimeSync()

useRealtimeSync(() => ({
  topics: [{ topic: predictionsTopics.orderbook({ marketId: id.value }), invalidate: [pq.markets.getOrderbook({ marketId: id.value }).queryKey] }],
}))