@etsoo/react 1.8.42 → 1.8.43
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/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/uses/useLocationState.d.ts +7 -0
- package/lib/cjs/uses/useLocationState.js +17 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/lib/mjs/uses/useLocationState.d.ts +7 -0
- package/lib/mjs/uses/useLocationState.js +14 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/uses/useLocationState.ts +17 -0
package/lib/cjs/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from "./uses/useAsyncState";
|
|
|
24
24
|
export * from "./uses/useCombinedRefs";
|
|
25
25
|
export * from "./uses/useDelayedExecutor";
|
|
26
26
|
export * from "./uses/useDimensions";
|
|
27
|
+
export * from "./uses/useLocationState";
|
|
27
28
|
export * from "./uses/useParamsEx";
|
|
28
29
|
export * from "./uses/useRefs";
|
|
29
30
|
export * from "./uses/useRequiredContext";
|
package/lib/cjs/index.js
CHANGED
|
@@ -45,6 +45,7 @@ __exportStar(require("./uses/useAsyncState"), exports);
|
|
|
45
45
|
__exportStar(require("./uses/useCombinedRefs"), exports);
|
|
46
46
|
__exportStar(require("./uses/useDelayedExecutor"), exports);
|
|
47
47
|
__exportStar(require("./uses/useDimensions"), exports);
|
|
48
|
+
__exportStar(require("./uses/useLocationState"), exports);
|
|
48
49
|
__exportStar(require("./uses/useParamsEx"), exports);
|
|
49
50
|
__exportStar(require("./uses/useRefs"), exports);
|
|
50
51
|
__exportStar(require("./uses/useRequiredContext"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocationState = useLocationState;
|
|
4
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
5
|
+
/**
|
|
6
|
+
* Location state
|
|
7
|
+
* @param T Type of state
|
|
8
|
+
* @returns State
|
|
9
|
+
* @throws Error if state is null or undefined
|
|
10
|
+
*/
|
|
11
|
+
function useLocationState() {
|
|
12
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
13
|
+
if (location.state == null) {
|
|
14
|
+
throw new Error(`useLocationState: ${location.pathname} state is required`);
|
|
15
|
+
}
|
|
16
|
+
return location.state;
|
|
17
|
+
}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from "./uses/useAsyncState";
|
|
|
24
24
|
export * from "./uses/useCombinedRefs";
|
|
25
25
|
export * from "./uses/useDelayedExecutor";
|
|
26
26
|
export * from "./uses/useDimensions";
|
|
27
|
+
export * from "./uses/useLocationState";
|
|
27
28
|
export * from "./uses/useParamsEx";
|
|
28
29
|
export * from "./uses/useRefs";
|
|
29
30
|
export * from "./uses/useRequiredContext";
|
package/lib/mjs/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./uses/useAsyncState";
|
|
|
29
29
|
export * from "./uses/useCombinedRefs";
|
|
30
30
|
export * from "./uses/useDelayedExecutor";
|
|
31
31
|
export * from "./uses/useDimensions";
|
|
32
|
+
export * from "./uses/useLocationState";
|
|
32
33
|
export * from "./uses/useParamsEx";
|
|
33
34
|
export * from "./uses/useRefs";
|
|
34
35
|
export * from "./uses/useRequiredContext";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLocation } from "react-router-dom";
|
|
2
|
+
/**
|
|
3
|
+
* Location state
|
|
4
|
+
* @param T Type of state
|
|
5
|
+
* @returns State
|
|
6
|
+
* @throws Error if state is null or undefined
|
|
7
|
+
*/
|
|
8
|
+
export function useLocationState() {
|
|
9
|
+
const location = useLocation();
|
|
10
|
+
if (location.state == null) {
|
|
11
|
+
throw new Error(`useLocationState: ${location.pathname} state is required`);
|
|
12
|
+
}
|
|
13
|
+
return location.state;
|
|
14
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from "./uses/useAsyncState";
|
|
|
39
39
|
export * from "./uses/useCombinedRefs";
|
|
40
40
|
export * from "./uses/useDelayedExecutor";
|
|
41
41
|
export * from "./uses/useDimensions";
|
|
42
|
+
export * from "./uses/useLocationState";
|
|
42
43
|
export * from "./uses/useParamsEx";
|
|
43
44
|
export * from "./uses/useRefs";
|
|
44
45
|
export * from "./uses/useRequiredContext";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useLocation } from "react-router-dom";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Location state
|
|
5
|
+
* @param T Type of state
|
|
6
|
+
* @returns State
|
|
7
|
+
* @throws Error if state is null or undefined
|
|
8
|
+
*/
|
|
9
|
+
export function useLocationState<T>() {
|
|
10
|
+
const location = useLocation();
|
|
11
|
+
|
|
12
|
+
if (location.state == null) {
|
|
13
|
+
throw new Error(`useLocationState: ${location.pathname} state is required`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return location.state as T;
|
|
17
|
+
}
|