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

安装

更新于 2026-11-02 Preact 查看英文原文 ↗

你可以通过 NPM 安装 Preact Query,
或者通过一个经典的 <script> 从 ESM.sh 获取。

NPM

Shell
1npm i @tanstack/preact-query

或

Shell
1pnpm add @tanstack/preact-query

或

Shell
1yarn add @tanstack/preact-query

或

Shell
1bun add @tanstack/preact-query

或

Shell
1deno add @tanstack/preact-query

Preact Query 兼容 Preact v10+。

想在下载前先试用?试试 简单 示例。

CDN

如果你未使用模块打包器或包管理器,也可以通过支持 ESM 的 CDN(例如 ESM.sh)使用该库。只需在 HTML 文件底部添加一个 <script type="module"> 标签:

HTML
1<script type="module">2  import { render } from 'https://esm.sh/preact@10.23.1'3  import { QueryClient } from 'https://esm.sh/@tanstack/ppreact-query'4</script>

要求

Preact Query 针对现代浏览器进行了优化。它兼容以下浏览器配置:

Code
1Chrome >= 912Firefox >= 903Edge >= 914Safari >= 155iOS >= 156Opera >= 77

根据你的运行环境,你可能需要添加 polyfill。若需支持较旧的浏览器,则需自行将该库从 node_modules 进行转译。

建议

建议同时使用我们的 ESLint Plugin Query,以帮助你在编码时发现错误和不一致之处。可通过以下方式安装:

Shell
1npm i -D @tanstack/eslint-plugin-query

或

Shell
1pnpm add -D @tanstack/eslint-plugin-query

或

Shell
1yarn add -D @tanstack/eslint-plugin-query

或

Shell
1bun add -D @tanstack/eslint-plugin-query

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

译自上游 59d11de