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.
Installation #
This utility comes as a separate package and is available under the '@tanstack/query-broadcast-client-experimental'
import.
Usage #
Import the broadcastQueryClient
function, and pass it your QueryClient
instance, and optionally, set a broadcastChannel
.
1import { broadcastQueryClient } from '@tanstack/query-broadcast-client-experimental'
2
3const queryClient = new QueryClient()
4
5broadcastQueryClient({
6 queryClient,
7 broadcastChannel: 'my-app',
8})
API #
broadcastQueryClient
#
Pass this function a QueryClient
instance and optionally, a broadcastChannel
.
1broadcastQueryClient({ queryClient, broadcastChannel })
Options
#
An object of options:
1interface broadcastQueryClient {
2 /** The QueryClient to sync */
3 queryClient: QueryClient
4 /** This is the unique channel name that will be used
5 * to communicate between tabs and windows */
6 broadcastChannel?: string
7 /** Options for the BroadcastChannel API */
8 options?: BroadcastChannelOptions
9}
The default options are:
1{
2 broadcastChannel = 'react-query',
3}