Open History to see the last commit
1---
2id: broadcastQueryClient
3title: broadcastQueryClient (Experimental)
4---
5β
6> 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.
7β
8`broadcastQueryClient` is a utility for broadcasting and syncing the state of your queryClient between browser tabs/windows with the same origin.
9β
10## Installation
11β
12This utility comes as a separate package and is available under the `'@tanstack/query-broadcast-client-experimental'` import.
13β
14## Usage
15β
16Import the `broadcastQueryClient` function, and pass it your `QueryClient` instance, and optionally, set a `broadcastChannel`.
17β
18```tsx
19import { broadcastQueryClient } from '@tanstack/query-broadcast-client-experimental'
20β
21const queryClient = new QueryClient()
22β
23broadcastQueryClient({
24 queryClient,
25 broadcastChannel: 'my-app',
26})
27```
28β
29## API
30β
31### `broadcastQueryClient`
32β
33Pass this function a `QueryClient` instance and optionally, a `broadcastChannel`.
34β
35```tsx
36broadcastQueryClient({ queryClient, broadcastChannel })
37```
38β
39### `Options`
40β
41An object of options:
42β
43```tsx
44interface BroadcastQueryClientOptions {
45 /** The QueryClient to sync */
46 queryClient: QueryClient
47 /** This is the unique channel name that will be used
48 * to communicate between tabs and windows */
49 broadcastChannel?: string
50 /** Options for the BroadcastChannel API */
51 options?: BroadcastChannelOptions
52}
53```
54β
55The default options are:
56β
57```tsx
58{
59 broadcastChannel = 'tanstack-query',
60}
61```