# @tanstack/react-query 中文文档

规范地址：https://npmcn.com/package/%40tanstack/react-query/

版本：5\.105\.2
npm 元数据更新时间：2026-11-02T13:57:23.002Z
中文译文更新时间：2026-11-02T15:40:27.064Z
软件包许可：MIT

本文由上游 README 机器翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40tanstack/react-query
原文对照：https://npmcn.com/package/%40tanstack/react-query/?lang=original
项目主页：https://tanstack.com/query
源码仓库：https://github.com/TanStack/query

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.8 MB，410 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：react ^18 \|\| ^19，@types/react ^18 \|\| ^19
- 首次发布：2022-07-19T13:33:05.988Z
- 最新版本发布：2026-11-02T13:57:22.684Z
- 已发布版本数：548（近 12 个月 77 个）

## 中文简介

用于管理、缓存和同步React中的异步和远程数据的钩子

## 安装

```sh
npm install @tanstack/react-query
```

也可以使用：`pnpm add @tanstack/react-query`、`yarn add @tanstack/react-query`、`bun add @tanstack/react-query`

## README

![](https://static.scarf.sh/a.png?x-pxid=be2d8a11-9712-4c1d-9963-580b2d4fb133) ![TanStack React Query](https://tanstack.com/api/readme/query.png?framework=react)

React中用于获取、缓存和更新异步数据的钩子

 [![#TanStack](https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack)](https://twitter.com/intent/tweet?button_hashtag=TanStack)[![](https://img.shields.io/badge/Discord-TanStack-%235865F2) ](https://discord.com/invite/WrRKjPJ)[![Release status](https://github.com/TanStack/query/actions/workflows/release.yml/badge.svg?branch=main) ](https://github.com/TanStack/query/actions/workflows/release.yml?query=branch%3Amain)[![](https://img.shields.io/npm/dm/@tanstack/query-core.svg) ](https://www.npmjs.com/package/@tanstack/query-core)[![](https://deno.bundlejs.com/?q=@tanstack/react-query&config={%22esbuild%22:{%22external%22:[%22react%22,%22react-dom%22]}}&badge=detailed) ](https://bundlejs.com/?q=%40tanstack%2Freact-query&config=%7B%22esbuild%22%3A%7B%22external%22%3A%5B%22react%22%2C%22react-dom%22%5D%7D%7D&badge=)[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg) ](https://npmcn.com/package/%40tanstack/react-query/#readme-badge)[![Join the discussion on Github](https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue) ](https://github.com/TanStack/query/discussions)[![Best of JS](https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=TanStack%2Fquery%26since=daily)](https://bestofjs.org/projects/tanstack-query)  [![](https://img.shields.io/github/stars/TanStack/query.svg?style=social&label=Star)](https://github.com/TanStack/query/)[![](https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow) ](https://twitter.com/tannerlinsley)[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)

喜欢这个图书馆吗？试一遍 [TanStack](https://tanstack.com/)！ [TanStack表](https://github.com/TanStack/table)， [TanStack路由器](https://github.com/tanstack/router)， [TanStack虚拟](https://github.com/tanstack/virtual)， [反应图](https://github.com/TanStack/react-charts)， [管理员反应](https://github.com/TanStack/ranger)

## 访问 [tanstack.com/query](https://tanstack.com/query) 文档，指南，API和更多！

## 快速的特点

-   传输/协议/后端无关的数据获取（REST, GraphQL, promises，等等！）
-   自动缓存+重新获取（stale-while-revalidate, Window Refocus, Polling/Realtime）
-   并行+相关查询
-   突变+响应式查询重取
-   多层缓存+自动垃圾收集
-   分页+基于游标的查询
-   Load-More +无限滚动查询w/滚动恢复
-   请求取消
-   [反应悬念](https://react.dev/reference/react/Suspense) + Fetch-As-You-Render查询预取
-   专用Devtools

### [成为赞助商！](https://github.com/sponsors/tannerlinsley/)

## 常见问题

### @tanstack/react-query 是什么？

用于管理、缓存和同步React中的异步和远程数据的钩子

### 如何安装 @tanstack/react-query？

在项目目录运行 npm install @tanstack/react-query，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（^18 \|\| ^19）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @tanstack/react-query 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @tanstack/react-query 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @tanstack/react-query 可以商用吗？

@tanstack/react-query 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @tanstack/react-query 还在维护吗？

最新版本 5\.105\.2 发布于 2026/11/02（今天）；至今共发布 548 个版本，其中过去 12 个月发布了 77 个；首次发布于 2022/07/19。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

