安装
你可以通过 NPM 安装 React Query,
或者使用一个经典的 <script>,通过 ESM.sh 引入。
NPM
Shell
1npm i @tanstack/react-query或
Shell
1pnpm add @tanstack/react-query或
Shell
1yarn add @tanstack/react-query或
Shell
1bun add @tanstack/react-query或
Shell
1deno add @tanstack/react-queryReact Query 兼容 React v18+,可在 ReactDOM 和 React Native 中使用。
CDN
如果你未使用模块打包器或包管理器,也可通过支持 ESM 的 CDN(例如 ESM.sh)引入本库。只需在 HTML 文件底部添加一个 <script type="module"> 标签:
HTML
1<script type="module">2 import React from 'https://esm.sh/react@18.2.0'3 import ReactDOM from 'https://esm.sh/react-dom@18.2.0'4 import { QueryClient } from 'https://esm.sh/@tanstack/react-query'5</script>你可在此处查阅不使用 JSX 使用 React 的说明。
系统要求
React 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