安装
你可以通过 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-queryPreact 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