
VERY IMPORTANT: This utility is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Use at your own risk. If you choose to rely on this in production in an experimental stage, please lock your version to a patch-level version to avoid unexpected breakages.
broadcastQueryClient is a utility for broadcasting and syncing the state of your queryClient between browser tabs/windows with the same origin.
This utility comes packaged with svelte-query and is available under the @sveltestack/svelte-query import.
However, this utility needs the broadcast-channel dependency to be available but it's not provided by this package.
So if you want to use this utility, you need to install it in your project:
# using npm:npm install broadcast-channel# using yarn:yarn add broadcast-channel# using pnpm:pnpm add broadcast-channel
Import the broadcastQueryClient function, and pass it your QueryClient instance, and optionally, set a broadcastChannel.
import { broadcastQueryClient } from '@sveltestack/svelte-query'const queryClient = new QueryClient()onMount(async () => {await broadcastQueryClient({queryClient,broadcastChannel: 'my-app',})});
broadcastQueryClientPass this function a QueryClient instance and optionally, a broadcastChannel.
await broadcastQueryClient({ queryClient, broadcastChannel })
OptionsAn object of options:
interface broadcastQueryClient {/** The QueryClient to sync */queryClient: QueryClient/** This is the unique channel name that will be used* to communicate between tabs and windows */broadcastChannel?: string}
The default options are:
{broadcastChannel = 'svelte-query',}
The latest TanStack news, articles, and resources, sent to your inbox.