Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

broadcastQueryClient.md

59 lines1.5 KB

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 packaged with `react-query` and is available under the `react-query/broadcastQueryClient-experimental` import.
13​
14## Usage
15​
16Import the `broadcastQueryClient` function, and pass it your `QueryClient` instance, and optionally, set a `broadcastChannel`.
17​
18```ts
19import { broadcastQueryClient } from 'react-query/broadcastQueryClient-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```ts
36broadcastQueryClient({ queryClient, broadcastChannel })
37```
38​
39### `Options`
40​
41An object of options:
42​
43```ts
44interface broadcastQueryClient {
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
51```
52​
53The default options are:
54​
55```ts
57 broadcastChannel = 'react-query',
59```