译零 TransZero · TanStack Query v4 中文文档
主站

broadcastQueryClient (Experimental)

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.

TypeScript
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.

TypeScript
1broadcastQueryClient({ queryClient, broadcastChannel })

Options

An object of options:

TypeScript
1interface broadcastQueryClient {2  /** The QueryClient to sync */3  queryClient: QueryClient4  /** This is the unique channel name that will be used5   * to communicate between tabs and windows */6  broadcastChannel?: string7}

The default options are:

TypeScript
1{2  broadcastChannel = 'react-query',3}

本页为 TanStack Query 文档(React 版)的非官方中文翻译,原文由上游团队维护,遵循 MIT 许可。 译文如有偏差,以英文原文为准。

本页译文取自社区中文版 react-query-web-i18n(MIT),非本站翻译,已停止更新,内容可能与当前 API 有出入。

译自上游 (未记录版本)