@etsoo/react 1.8.36 → 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.
@@ -9,7 +9,6 @@ const react_router_dom_1 = require("react-router-dom");
9
9
  * @param storage Storage
10
10
  */
11
11
  function useSearchParamsWithCache(cacheKey, storage) {
12
- const [sp] = (0, react_router_dom_1.useSearchParams)();
13
12
  const data = {};
14
13
  if (cacheKey) {
15
14
  storage ?? (storage = new shared_1.WindowStorage());
@@ -18,6 +17,9 @@ function useSearchParamsWithCache(cacheKey, storage) {
18
17
  Object.assign(data, paras);
19
18
  }
20
19
  }
21
- Object.assign(data, Object.fromEntries(sp.entries()));
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
+ }
22
24
  return data;
23
25
  }
@@ -1,12 +1,11 @@
1
1
  import { WindowStorage } from "@etsoo/shared";
2
- import { useSearchParams } from "react-router-dom";
2
+ import { useInRouterContext, useSearchParams } from "react-router-dom";
3
3
  /**
4
4
  * Read search parameters with cache
5
5
  * @param cacheKey Cache key
6
6
  * @param storage Storage
7
7
  */
8
8
  export function useSearchParamsWithCache(cacheKey, storage) {
9
- const [sp] = useSearchParams();
10
9
  const data = {};
11
10
  if (cacheKey) {
12
11
  storage ?? (storage = new WindowStorage());
@@ -15,6 +14,9 @@ export function useSearchParamsWithCache(cacheKey, storage) {
15
14
  Object.assign(data, paras);
16
15
  }
17
16
  }
18
- Object.assign(data, Object.fromEntries(sp.entries()));
17
+ if (useInRouterContext()) {
18
+ const [sp] = useSearchParams();
19
+ Object.assign(data, Object.fromEntries(sp.entries()));
20
+ }
19
21
  return data;
20
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.36",
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",
@@ -1,5 +1,5 @@
1
1
  import { IStorage, WindowStorage } from "@etsoo/shared";
2
- import { useSearchParams } from "react-router-dom";
2
+ import { useInRouterContext, useSearchParams } from "react-router-dom";
3
3
 
4
4
  /**
5
5
  * Read search parameters with cache
@@ -10,8 +10,6 @@ export function useSearchParamsWithCache(
10
10
  cacheKey?: string,
11
11
  storage?: IStorage
12
12
  ) {
13
- const [sp] = useSearchParams();
14
-
15
13
  const data = {};
16
14
 
17
15
  if (cacheKey) {
@@ -22,7 +20,10 @@ export function useSearchParamsWithCache(
22
20
  }
23
21
  }
24
22
 
25
- Object.assign(data, Object.fromEntries(sp.entries()));
23
+ if (useInRouterContext()) {
24
+ const [sp] = useSearchParams();
25
+ Object.assign(data, Object.fromEntries(sp.entries()));
26
+ }
26
27
 
27
28
  return data;
28
29
  }