@etsoo/react 1.8.41 → 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/components/ScrollerGrid.js +3 -1
- package/lib/cjs/components/ScrollerList.js +3 -1
- 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/components/ScrollerGrid.js +3 -1
- package/lib/mjs/components/ScrollerList.js +3 -1
- 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/components/ScrollerGrid.tsx +6 -1
- package/src/components/ScrollerList.tsx +5 -1
- package/src/index.ts +1 -0
- package/src/uses/useLocationState.ts +17 -0
|
@@ -41,7 +41,9 @@ const ScrollerGrid = (props) => {
|
|
|
41
41
|
// Load data
|
|
42
42
|
const loadDataLocal = (pageAdd = 1) => {
|
|
43
43
|
// Prevent multiple loadings
|
|
44
|
-
if (!refs.current.hasNextPage ||
|
|
44
|
+
if (!refs.current.hasNextPage ||
|
|
45
|
+
refs.current.isNextPageLoading ||
|
|
46
|
+
refs.current.isMounted === false)
|
|
45
47
|
return;
|
|
46
48
|
// Update state
|
|
47
49
|
refs.current.isNextPageLoading = true;
|
|
@@ -59,7 +59,9 @@ const ScrollerList = (props) => {
|
|
|
59
59
|
// Load data
|
|
60
60
|
const loadDataLocal = (pageAdd = 1) => {
|
|
61
61
|
// Prevent multiple loadings
|
|
62
|
-
if (!stateRefs.current.hasNextPage ||
|
|
62
|
+
if (!stateRefs.current.hasNextPage ||
|
|
63
|
+
stateRefs.current.isNextPageLoading ||
|
|
64
|
+
stateRefs.current.isMounted === false)
|
|
63
65
|
return;
|
|
64
66
|
// Update state
|
|
65
67
|
stateRefs.current.isNextPageLoading = true;
|
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
|
+
}
|
|
@@ -35,7 +35,9 @@ export const ScrollerGrid = (props) => {
|
|
|
35
35
|
// Load data
|
|
36
36
|
const loadDataLocal = (pageAdd = 1) => {
|
|
37
37
|
// Prevent multiple loadings
|
|
38
|
-
if (!refs.current.hasNextPage ||
|
|
38
|
+
if (!refs.current.hasNextPage ||
|
|
39
|
+
refs.current.isNextPageLoading ||
|
|
40
|
+
refs.current.isMounted === false)
|
|
39
41
|
return;
|
|
40
42
|
// Update state
|
|
41
43
|
refs.current.isNextPageLoading = true;
|
|
@@ -53,7 +53,9 @@ export const ScrollerList = (props) => {
|
|
|
53
53
|
// Load data
|
|
54
54
|
const loadDataLocal = (pageAdd = 1) => {
|
|
55
55
|
// Prevent multiple loadings
|
|
56
|
-
if (!stateRefs.current.hasNextPage ||
|
|
56
|
+
if (!stateRefs.current.hasNextPage ||
|
|
57
|
+
stateRefs.current.isNextPageLoading ||
|
|
58
|
+
stateRefs.current.isMounted === false)
|
|
57
59
|
return;
|
|
58
60
|
// Update state
|
|
59
61
|
stateRefs.current.isNextPageLoading = true;
|
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
|
@@ -206,7 +206,12 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
|
|
|
206
206
|
// Load data
|
|
207
207
|
const loadDataLocal = (pageAdd: number = 1) => {
|
|
208
208
|
// Prevent multiple loadings
|
|
209
|
-
if (
|
|
209
|
+
if (
|
|
210
|
+
!refs.current.hasNextPage ||
|
|
211
|
+
refs.current.isNextPageLoading ||
|
|
212
|
+
refs.current.isMounted === false
|
|
213
|
+
)
|
|
214
|
+
return;
|
|
210
215
|
|
|
211
216
|
// Update state
|
|
212
217
|
refs.current.isNextPageLoading = true;
|
|
@@ -164,7 +164,11 @@ export const ScrollerList = <T extends object>(props: ScrollerListProps<T>) => {
|
|
|
164
164
|
// Load data
|
|
165
165
|
const loadDataLocal = (pageAdd: number = 1) => {
|
|
166
166
|
// Prevent multiple loadings
|
|
167
|
-
if (
|
|
167
|
+
if (
|
|
168
|
+
!stateRefs.current.hasNextPage ||
|
|
169
|
+
stateRefs.current.isNextPageLoading ||
|
|
170
|
+
stateRefs.current.isMounted === false
|
|
171
|
+
)
|
|
168
172
|
return;
|
|
169
173
|
|
|
170
174
|
// Update state
|
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
|
+
}
|