@pdg/react-hook 1.0.22 → 1.0.24
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/dist/clearIntervalRef.d.ts +4 -0
- package/dist/clearTimeoutRef.d.ts +4 -0
- package/dist/index.d.ts +17 -13
- package/dist/index.esm.js +51 -4
- package/dist/index.js +51 -4
- package/dist/useAutoForceUpdate.d.ts +2 -1
- package/dist/useAutoUpdateLayoutRef.d.ts +2 -1
- package/dist/useAutoUpdateLayoutRefState.d.ts +4 -3
- package/dist/useAutoUpdateLayoutState.d.ts +4 -3
- package/dist/useAutoUpdateRef.d.ts +2 -1
- package/dist/useAutoUpdateRefState.d.ts +4 -3
- package/dist/useAutoUpdateState.d.ts +4 -3
- package/dist/useFirstSkipEffect.d.ts +2 -1
- package/dist/useFirstSkipLayoutEffect.d.ts +2 -1
- package/dist/useForceUpdate.d.ts +2 -1
- package/dist/useForwardRef.d.ts +2 -1
- package/dist/useIntervalRef.d.ts +8 -0
- package/dist/useLayoutPerformance.d.ts +2 -1
- package/dist/usePerformance.d.ts +2 -1
- package/dist/useTimeoutRef.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
1
|
+
export * from './useAutoUpdateState';
|
|
2
|
+
export * from './useAutoUpdateLayoutState';
|
|
3
|
+
export * from './useFirstSkipEffect';
|
|
4
|
+
export * from './useFirstSkipLayoutEffect';
|
|
5
|
+
export * from './useAutoUpdateRefState';
|
|
6
|
+
export * from './useAutoUpdateLayoutRefState';
|
|
7
|
+
export * from './useForwardRef';
|
|
8
|
+
export * from './useAutoUpdateRef';
|
|
9
|
+
export * from './useAutoUpdateLayoutRef';
|
|
10
|
+
export * from './usePerformance';
|
|
11
|
+
export * from './useLayoutPerformance';
|
|
12
|
+
export * from './useAutoForceUpdate';
|
|
13
|
+
export * from './useForceUpdate';
|
|
14
|
+
export * from './useTimeoutRef';
|
|
15
|
+
export * from './clearTimeoutRef';
|
|
16
|
+
export * from './useIntervalRef';
|
|
17
|
+
export * from './clearIntervalRef';
|
package/dist/index.esm.js
CHANGED
|
@@ -174,9 +174,56 @@ function useAutoUpdateLayoutRefState(state, callback) {
|
|
|
174
174
|
clearInterval(tm);
|
|
175
175
|
};
|
|
176
176
|
}, [interval]);
|
|
177
|
-
}function
|
|
178
|
-
|
|
177
|
+
}function clearTimeoutRef(ref) {
|
|
178
|
+
if (ref.current) {
|
|
179
|
+
clearTimeout(ref.current);
|
|
180
|
+
ref.current = undefined;
|
|
181
|
+
}
|
|
182
|
+
}function useTimeoutRef() {
|
|
183
|
+
var ref = useRef();
|
|
184
|
+
useEffect(function () {
|
|
185
|
+
return function () {
|
|
186
|
+
clearTimeoutRef(ref);
|
|
187
|
+
};
|
|
188
|
+
}, []);
|
|
189
|
+
var setTimeoutFunc = useCallback(function (callback, ms) {
|
|
190
|
+
clearTimeoutRef(ref);
|
|
191
|
+
ref.current = setTimeout(function () {
|
|
192
|
+
ref.current = undefined;
|
|
193
|
+
callback();
|
|
194
|
+
}, ms);
|
|
195
|
+
}, []);
|
|
196
|
+
return [ref, setTimeoutFunc];
|
|
197
|
+
}function useForceUpdate(delay) {
|
|
198
|
+
var _a = useTimeoutRef(), setDelayTimeout = _a[1];
|
|
199
|
+
var _b = useState(0), setValue = _b[1];
|
|
179
200
|
return useCallback(function () {
|
|
180
|
-
|
|
201
|
+
if (delay) {
|
|
202
|
+
setDelayTimeout(function () {
|
|
203
|
+
setValue(function (old) { return old + 1; });
|
|
204
|
+
}, delay);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
setValue(function (old) { return old + 1; });
|
|
208
|
+
}
|
|
209
|
+
}, []);
|
|
210
|
+
}function clearIntervalRef(ref) {
|
|
211
|
+
if (ref.current) {
|
|
212
|
+
clearInterval(ref.current);
|
|
213
|
+
ref.current = undefined;
|
|
214
|
+
}
|
|
215
|
+
}function useIntervalRef() {
|
|
216
|
+
var ref = useRef();
|
|
217
|
+
useEffect(function () {
|
|
218
|
+
return function () {
|
|
219
|
+
clearIntervalRef(ref);
|
|
220
|
+
};
|
|
221
|
+
}, []);
|
|
222
|
+
var setIntervalFunc = useCallback(function (callback, ms) {
|
|
223
|
+
clearIntervalRef(ref);
|
|
224
|
+
ref.current = setInterval(function () {
|
|
225
|
+
callback(ref);
|
|
226
|
+
}, ms);
|
|
181
227
|
}, []);
|
|
182
|
-
|
|
228
|
+
return [ref, setIntervalFunc];
|
|
229
|
+
}export{clearIntervalRef,clearTimeoutRef,useAutoForceUpdate,useAutoUpdateLayoutRef,useAutoUpdateLayoutRefState,useAutoUpdateLayoutState,useAutoUpdateRef,useAutoUpdateRefState,useAutoUpdateState,useFirstSkipEffect,useFirstSkipLayoutEffect,useForceUpdate,useForwardRef,useIntervalRef,useLayoutPerformance,usePerformance,useTimeoutRef};
|
package/dist/index.js
CHANGED
|
@@ -174,9 +174,56 @@ function useAutoUpdateLayoutRefState(state, callback) {
|
|
|
174
174
|
clearInterval(tm);
|
|
175
175
|
};
|
|
176
176
|
}, [interval]);
|
|
177
|
-
}function
|
|
178
|
-
|
|
177
|
+
}function clearTimeoutRef(ref) {
|
|
178
|
+
if (ref.current) {
|
|
179
|
+
clearTimeout(ref.current);
|
|
180
|
+
ref.current = undefined;
|
|
181
|
+
}
|
|
182
|
+
}function useTimeoutRef() {
|
|
183
|
+
var ref = react.useRef();
|
|
184
|
+
react.useEffect(function () {
|
|
185
|
+
return function () {
|
|
186
|
+
clearTimeoutRef(ref);
|
|
187
|
+
};
|
|
188
|
+
}, []);
|
|
189
|
+
var setTimeoutFunc = react.useCallback(function (callback, ms) {
|
|
190
|
+
clearTimeoutRef(ref);
|
|
191
|
+
ref.current = setTimeout(function () {
|
|
192
|
+
ref.current = undefined;
|
|
193
|
+
callback();
|
|
194
|
+
}, ms);
|
|
195
|
+
}, []);
|
|
196
|
+
return [ref, setTimeoutFunc];
|
|
197
|
+
}function useForceUpdate(delay) {
|
|
198
|
+
var _a = useTimeoutRef(), setDelayTimeout = _a[1];
|
|
199
|
+
var _b = react.useState(0), setValue = _b[1];
|
|
179
200
|
return react.useCallback(function () {
|
|
180
|
-
|
|
201
|
+
if (delay) {
|
|
202
|
+
setDelayTimeout(function () {
|
|
203
|
+
setValue(function (old) { return old + 1; });
|
|
204
|
+
}, delay);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
setValue(function (old) { return old + 1; });
|
|
208
|
+
}
|
|
209
|
+
}, []);
|
|
210
|
+
}function clearIntervalRef(ref) {
|
|
211
|
+
if (ref.current) {
|
|
212
|
+
clearInterval(ref.current);
|
|
213
|
+
ref.current = undefined;
|
|
214
|
+
}
|
|
215
|
+
}function useIntervalRef() {
|
|
216
|
+
var ref = react.useRef();
|
|
217
|
+
react.useEffect(function () {
|
|
218
|
+
return function () {
|
|
219
|
+
clearIntervalRef(ref);
|
|
220
|
+
};
|
|
221
|
+
}, []);
|
|
222
|
+
var setIntervalFunc = react.useCallback(function (callback, ms) {
|
|
223
|
+
clearIntervalRef(ref);
|
|
224
|
+
ref.current = setInterval(function () {
|
|
225
|
+
callback(ref);
|
|
226
|
+
}, ms);
|
|
181
227
|
}, []);
|
|
182
|
-
|
|
228
|
+
return [ref, setIntervalFunc];
|
|
229
|
+
}exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoForceUpdate=useAutoForceUpdate;exports.useAutoUpdateLayoutRef=useAutoUpdateLayoutRef;exports.useAutoUpdateLayoutRefState=useAutoUpdateLayoutRefState;exports.useAutoUpdateLayoutState=useAutoUpdateLayoutState;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useAutoUpdateRefState=useAutoUpdateRefState;exports.useAutoUpdateState=useAutoUpdateState;exports.useFirstSkipEffect=useFirstSkipEffect;exports.useFirstSkipLayoutEffect=useFirstSkipLayoutEffect;exports.useForceUpdate=useForceUpdate;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useLayoutPerformance=useLayoutPerformance;exports.usePerformance=usePerformance;exports.useTimeoutRef=useTimeoutRef;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function useAutoForceUpdate(name: string, interval: number): void;
|
|
2
|
+
export default useAutoForceUpdate;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MutableRefObject, SetStateAction } from 'react';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export declare function useAutoUpdateLayoutRefState<T>(state: Exclude<T, (...args: any[]) => any>): [MutableRefObject<T>, T, (value: SetStateAction<T>) => T];
|
|
3
|
+
export declare function useAutoUpdateLayoutRefState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [MutableRefObject<T>, T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
|
|
4
|
+
export declare function useAutoUpdateLayoutRefState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
|
|
5
5
|
MutableRefObject<T extends never ? StateT : T>,
|
|
6
6
|
T extends never ? StateT : T,
|
|
7
7
|
(value: SetStateAction<T | StateT>, skipCallback?: boolean) => T extends never ? StateT : T
|
|
8
8
|
];
|
|
9
|
+
export default useAutoUpdateLayoutRefState;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SetStateAction } from 'react';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export declare function useAutoUpdateLayoutState<T>(state: Exclude<T, (...args: any[]) => any>): [T, (value: SetStateAction<T>) => T];
|
|
3
|
+
export declare function useAutoUpdateLayoutState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
|
|
4
|
+
export declare function useAutoUpdateLayoutState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
|
|
5
5
|
T extends never ? StateT : T,
|
|
6
6
|
(value: SetStateAction<T | StateT>, skipCallback?: boolean) => T extends never ? StateT : T
|
|
7
7
|
];
|
|
8
|
+
export default useAutoUpdateLayoutState;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MutableRefObject, SetStateAction } from 'react';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export declare function useAutoUpdateRefState<T>(state: Exclude<T, (...args: any[]) => any>): [MutableRefObject<T>, T, (value: SetStateAction<T>) => T];
|
|
3
|
+
export declare function useAutoUpdateRefState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [MutableRefObject<T>, T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
|
|
4
|
+
export declare function useAutoUpdateRefState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
|
|
5
5
|
MutableRefObject<T extends never ? StateT : T>,
|
|
6
6
|
T extends never ? StateT : T,
|
|
7
7
|
(value: SetStateAction<T | StateT>, skipCallback?: boolean) => T extends never ? StateT : T
|
|
8
8
|
];
|
|
9
|
+
export default useAutoUpdateRefState;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SetStateAction } from 'react';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export declare function useAutoUpdateState<T>(state: Exclude<T, (...args: any[]) => any>): [T, (value: SetStateAction<T>) => T];
|
|
3
|
+
export declare function useAutoUpdateState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
|
|
4
|
+
export declare function useAutoUpdateState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
|
|
5
5
|
T extends never ? StateT : T,
|
|
6
6
|
(value: SetStateAction<T | StateT>, skipCallback?: boolean) => T extends never ? StateT : T
|
|
7
7
|
];
|
|
8
|
+
export default useAutoUpdateState;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
-
export
|
|
2
|
+
export declare function useFirstSkipEffect(effect: EffectCallback, deps?: DependencyList): void;
|
|
3
|
+
export default useFirstSkipEffect;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
-
export
|
|
2
|
+
export declare function useFirstSkipLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
|
|
3
|
+
export default useFirstSkipLayoutEffect;
|
package/dist/useForceUpdate.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function useForceUpdate(delay?: number): () => void;
|
|
2
|
+
export default useForceUpdate;
|
package/dist/useForwardRef.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type UseIntervalReturnValue = [
|
|
4
|
+
React.MutableRefObject<NodeJS.Timeout | undefined>,
|
|
5
|
+
(callback: (ref: React.MutableRefObject<NodeJS.Timeout | undefined>) => void, ms?: number) => void
|
|
6
|
+
];
|
|
7
|
+
export declare function useIntervalRef(): UseIntervalReturnValue;
|
|
8
|
+
export default useIntervalRef;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function useLayoutPerformance(name: string): void;
|
|
2
|
+
export default useLayoutPerformance;
|
package/dist/usePerformance.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function usePerformance(name: string): void;
|
|
2
|
+
export default usePerformance;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type UseTimeoutReturnValue = [
|
|
4
|
+
React.MutableRefObject<NodeJS.Timeout | undefined>,
|
|
5
|
+
(callback: (args: void) => void, ms?: number) => void
|
|
6
|
+
];
|
|
7
|
+
export declare function useTimeoutRef(): UseTimeoutReturnValue;
|
|
8
|
+
export default useTimeoutRef;
|