@etsoo/react 1.8.35 → 1.8.37

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.
@@ -28,6 +28,7 @@ export * from "./uses/useParamsEx";
28
28
  export * from "./uses/useRefs";
29
29
  export * from "./uses/useRequiredContext";
30
30
  export * from "./uses/useSearchParamsEx";
31
+ export * from "./uses/useSearchParamsWithCache";
31
32
  export * from "./uses/useTimeout";
32
33
  export * from "./uses/useWindowScroll";
33
34
  export * from "./uses/useWindowSize";
package/lib/cjs/index.js CHANGED
@@ -49,6 +49,7 @@ __exportStar(require("./uses/useParamsEx"), exports);
49
49
  __exportStar(require("./uses/useRefs"), exports);
50
50
  __exportStar(require("./uses/useRequiredContext"), exports);
51
51
  __exportStar(require("./uses/useSearchParamsEx"), exports);
52
+ __exportStar(require("./uses/useSearchParamsWithCache"), exports);
52
53
  __exportStar(require("./uses/useTimeout"), exports);
53
54
  __exportStar(require("./uses/useWindowScroll"), exports);
54
55
  __exportStar(require("./uses/useWindowSize"), exports);
@@ -0,0 +1,7 @@
1
+ import { IStorage } from "@etsoo/shared";
2
+ /**
3
+ * Read search parameters with cache
4
+ * @param cacheKey Cache key
5
+ * @param storage Storage
6
+ */
7
+ export declare function useSearchParamsWithCache(cacheKey?: string, storage?: IStorage): {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchParamsWithCache = useSearchParamsWithCache;
4
+ const shared_1 = require("@etsoo/shared");
5
+ const react_router_dom_1 = require("react-router-dom");
6
+ /**
7
+ * Read search parameters with cache
8
+ * @param cacheKey Cache key
9
+ * @param storage Storage
10
+ */
11
+ function useSearchParamsWithCache(cacheKey, storage) {
12
+ const data = {};
13
+ if (cacheKey) {
14
+ storage ?? (storage = new shared_1.WindowStorage());
15
+ const paras = storage.getObject(cacheKey);
16
+ if (paras) {
17
+ Object.assign(data, paras);
18
+ }
19
+ }
20
+ if ((0, react_router_dom_1.useInRouterContext)()) {
21
+ const [sp] = (0, react_router_dom_1.useSearchParams)();
22
+ Object.assign(data, Object.fromEntries(sp.entries()));
23
+ }
24
+ return data;
25
+ }
@@ -28,6 +28,7 @@ export * from "./uses/useParamsEx";
28
28
  export * from "./uses/useRefs";
29
29
  export * from "./uses/useRequiredContext";
30
30
  export * from "./uses/useSearchParamsEx";
31
+ export * from "./uses/useSearchParamsWithCache";
31
32
  export * from "./uses/useTimeout";
32
33
  export * from "./uses/useWindowScroll";
33
34
  export * from "./uses/useWindowSize";
package/lib/mjs/index.js CHANGED
@@ -33,6 +33,7 @@ export * from "./uses/useParamsEx";
33
33
  export * from "./uses/useRefs";
34
34
  export * from "./uses/useRequiredContext";
35
35
  export * from "./uses/useSearchParamsEx";
36
+ export * from "./uses/useSearchParamsWithCache";
36
37
  export * from "./uses/useTimeout";
37
38
  export * from "./uses/useWindowScroll";
38
39
  export * from "./uses/useWindowSize";
@@ -0,0 +1,7 @@
1
+ import { IStorage } from "@etsoo/shared";
2
+ /**
3
+ * Read search parameters with cache
4
+ * @param cacheKey Cache key
5
+ * @param storage Storage
6
+ */
7
+ export declare function useSearchParamsWithCache(cacheKey?: string, storage?: IStorage): {};
@@ -0,0 +1,22 @@
1
+ import { WindowStorage } from "@etsoo/shared";
2
+ import { useInRouterContext, useSearchParams } from "react-router-dom";
3
+ /**
4
+ * Read search parameters with cache
5
+ * @param cacheKey Cache key
6
+ * @param storage Storage
7
+ */
8
+ export function useSearchParamsWithCache(cacheKey, storage) {
9
+ const data = {};
10
+ if (cacheKey) {
11
+ storage ?? (storage = new WindowStorage());
12
+ const paras = storage.getObject(cacheKey);
13
+ if (paras) {
14
+ Object.assign(data, paras);
15
+ }
16
+ }
17
+ if (useInRouterContext()) {
18
+ const [sp] = useSearchParams();
19
+ Object.assign(data, Object.fromEntries(sp.entries()));
20
+ }
21
+ return data;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.35",
3
+ "version": "1.8.37",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -42,7 +42,7 @@
42
42
  "@emotion/styled": "^11.13.5",
43
43
  "@etsoo/appscript": "^1.6.21",
44
44
  "@etsoo/notificationbase": "^1.1.60",
45
- "@etsoo/shared": "^1.2.64",
45
+ "@etsoo/shared": "^1.2.66",
46
46
  "react": "^18.3.1",
47
47
  "react-dom": "^18.3.1",
48
48
  "react-router-dom": "^7.4.1",
@@ -60,9 +60,9 @@
60
60
  "@babel/preset-env": "^7.26.9",
61
61
  "@babel/runtime-corejs3": "^7.27.0",
62
62
  "@testing-library/jest-dom": "^6.6.3",
63
- "@testing-library/react": "^16.2.0",
63
+ "@testing-library/react": "^16.3.0",
64
64
  "@types/react": "^18.3.20",
65
- "@types/react-dom": "^18.3.1",
65
+ "@types/react-dom": "^18.3.6",
66
66
  "@types/react-window": "^1.8.8",
67
67
  "@vitejs/plugin-react": "^4.3.4",
68
68
  "jsdom": "^26.0.0",
package/src/index.ts CHANGED
@@ -43,6 +43,7 @@ export * from "./uses/useParamsEx";
43
43
  export * from "./uses/useRefs";
44
44
  export * from "./uses/useRequiredContext";
45
45
  export * from "./uses/useSearchParamsEx";
46
+ export * from "./uses/useSearchParamsWithCache";
46
47
  export * from "./uses/useTimeout";
47
48
  export * from "./uses/useWindowScroll";
48
49
  export * from "./uses/useWindowSize";
@@ -0,0 +1,29 @@
1
+ import { IStorage, WindowStorage } from "@etsoo/shared";
2
+ import { useInRouterContext, useSearchParams } from "react-router-dom";
3
+
4
+ /**
5
+ * Read search parameters with cache
6
+ * @param cacheKey Cache key
7
+ * @param storage Storage
8
+ */
9
+ export function useSearchParamsWithCache(
10
+ cacheKey?: string,
11
+ storage?: IStorage
12
+ ) {
13
+ const data = {};
14
+
15
+ if (cacheKey) {
16
+ storage ??= new WindowStorage();
17
+ const paras = storage.getObject(cacheKey);
18
+ if (paras) {
19
+ Object.assign(data, paras);
20
+ }
21
+ }
22
+
23
+ if (useInRouterContext()) {
24
+ const [sp] = useSearchParams();
25
+ Object.assign(data, Object.fromEntries(sp.entries()));
26
+ }
27
+
28
+ return data;
29
+ }