@iquji-web/web-query 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @iquji-web/web-query
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
简体中文 | [English](README.en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
基于 TanStack React Query 的标准化查询状态管理客户端,提供合理的默认缓存策略、窗口聚焦抑制与针对认证失效(401/403)的不重试保护。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @iquji-web/web-query @tanstack/react-query
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 核心特性与使用
|
|
18
|
+
|
|
19
|
+
### 1. 创建 Client 与注入 Provider
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { createIqujiQueryClient, IqujiQueryClientProvider } from "@iquji-web/web-query";
|
|
23
|
+
|
|
24
|
+
// 预设默认:staleTime=30s, gcTime=5m, 401/403 自动中断重试
|
|
25
|
+
const queryClient = createIqujiQueryClient();
|
|
26
|
+
|
|
27
|
+
export function App({ children }) {
|
|
28
|
+
return (
|
|
29
|
+
<IqujiQueryClientProvider client={queryClient}>
|
|
30
|
+
{children}
|
|
31
|
+
</IqujiQueryClientProvider>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. 重试策略判断函数
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { shouldRetryIqujiQuery, isAuthorizationQueryError } from "@iquji-web/web-query";
|
|
40
|
+
|
|
41
|
+
// 自定义查询配置
|
|
42
|
+
const customClient = createIqujiQueryClient({
|
|
43
|
+
defaultOptions: {
|
|
44
|
+
queries: {
|
|
45
|
+
retry: (failureCount, error) => {
|
|
46
|
+
if (isAuthorizationQueryError(error)) return false;
|
|
47
|
+
return failureCount < 3;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 开发与构建
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
bun install --frozen-lockfile
|
|
60
|
+
bun run build # 编译打包到 dist/
|
|
61
|
+
bun run typecheck # 类型校验
|
|
62
|
+
bun run test # 单元测试
|
|
63
|
+
bun run check # 自动化完整自检
|
|
64
|
+
```
|