@flow97/react-toolkit 0.0.3 → 0.0.5
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/CHANGELOG.md +12 -0
- package/lib/index.css +1 -1028
- package/lib/index.d.ts +20 -3
- package/lib/index.js +3 -13032
- package/lib/index.js.map +1 -1
- package/locale/context.js +2 -1473
- package/locale/hooks.js +18 -3755
- package/locale/index.js +18 -3755
- package/package.json +1 -1
- package/lib/index.css.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -87,6 +87,11 @@ interface KeepAliveProps {
|
|
|
87
87
|
* 使用 React 19 Activity API 实现组件状态缓存,避免路由切换时重新挂载
|
|
88
88
|
* 支持路由级别的自动缓存:如果不提供 cacheKey,会自动使用当前路由路径作为缓存 key
|
|
89
89
|
*
|
|
90
|
+
* **重要说明:**
|
|
91
|
+
* - React Activity 会保留组件的状态(state),组件不会被卸载和重新挂载
|
|
92
|
+
* - 但是当 Activity 从 hidden 切换到 visible 时,会重新执行副作用(useEffect)
|
|
93
|
+
* - 这意味着组件的状态会保留,但 useEffect 会重新运行,需要根据业务需求处理副作用
|
|
94
|
+
*
|
|
90
95
|
* @example
|
|
91
96
|
* ```tsx
|
|
92
97
|
* // 手动指定缓存 key
|
|
@@ -125,8 +130,6 @@ interface KeepAliveCacheItem {
|
|
|
125
130
|
element: ReactNode;
|
|
126
131
|
/** 是否激活 */
|
|
127
132
|
active: boolean;
|
|
128
|
-
/** 缓存时间戳 */
|
|
129
|
-
timestamp: number;
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
132
135
|
* KeepAlive 上下文类型
|
|
@@ -172,12 +175,15 @@ declare function useKeepAliveContext(): KeepAliveContextType;
|
|
|
172
175
|
* useKeepAlive Hook
|
|
173
176
|
* 用于控制 KeepAlive 缓存
|
|
174
177
|
*
|
|
178
|
+
* 如果 KeepAliveProvider 不存在,返回 no-op 实现,不会报错
|
|
179
|
+
* 这样可以在未启用 KeepAlive 的项目中正常使用
|
|
180
|
+
*
|
|
175
181
|
* @example
|
|
176
182
|
* ```tsx
|
|
177
183
|
* const { clearCache, removeCache, getCacheKeys } = useKeepAlive()
|
|
178
184
|
*
|
|
179
185
|
* const handleClearAll = () => {
|
|
180
|
-
* clearCache() //
|
|
186
|
+
* clearCache() // 清除所有缓存(如果 KeepAliveProvider 不存在,则无操作)
|
|
181
187
|
* }
|
|
182
188
|
*
|
|
183
189
|
* const handleClearSpecific = () => {
|
|
@@ -186,6 +192,17 @@ declare function useKeepAliveContext(): KeepAliveContextType;
|
|
|
186
192
|
* ```
|
|
187
193
|
*/
|
|
188
194
|
declare function useKeepAlive(): {
|
|
195
|
+
cache: any;
|
|
196
|
+
removeCache: () => void;
|
|
197
|
+
clearCache: () => void;
|
|
198
|
+
clearCacheByPath: () => void;
|
|
199
|
+
clearCurrentCache: () => void;
|
|
200
|
+
getCacheKeys: () => never[];
|
|
201
|
+
getAllCache: () => never[];
|
|
202
|
+
getCache: () => undefined;
|
|
203
|
+
activateCache: () => void;
|
|
204
|
+
deactivateCache: () => void;
|
|
205
|
+
} | {
|
|
189
206
|
cache: Map<string, KeepAliveCacheItem>;
|
|
190
207
|
removeCache: (key: string) => void;
|
|
191
208
|
clearCache: () => void;
|