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 withsetQueryData, because the message is incomplete. The query refetches the balance over HTTP; - on each notification, invalidates the user's
notificationsqueries; - on a topic's
onResync(after a reconnection), invalidates what it feeds:wallet(balance) ornotifications(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] }],
}))