@pdg/react-hook 1.0.21 → 1.0.23

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import React from 'react';
3
+ export declare function clearIntervalRef(ref: React.MutableRefObject<NodeJS.Timeout | undefined>): void;
4
+ export default clearIntervalRef;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import React from 'react';
3
+ export declare function clearTimeoutRef(ref: React.MutableRefObject<NodeJS.Timeout | undefined>): void;
4
+ export default clearTimeoutRef;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
- export { default as useAutoUpdateState } from './useAutoUpdateState';
2
- export { default as useAutoUpdateLayoutState } from './useAutoUpdateLayoutState';
3
- export { default as useFirstSkipEffect } from './useFirstSkipEffect';
4
- export { default as useFirstSkipLayoutEffect } from './useFirstSkipLayoutEffect';
5
- export { default as useAutoUpdateRefState } from './useAutoUpdateRefState';
6
- export { default as useAutoUpdateLayoutRefState } from './useAutoUpdateLayoutRefState';
7
- export { default as useForwardRef } from './useForwardRef';
8
- export { default as useAutoUpdateRef } from './useAutoUpdateRef';
9
- export { default as useAutoUpdateLayoutRef } from './useAutoUpdateLayoutRef';
10
- export { default as usePerformance } from './usePerformance';
11
- export { default as useLayoutPerformance } from './useLayoutPerformance';
12
- export { default as useAutoForceUpdate } from './useAutoForceUpdate';
13
- export { default as useForceUpdate } from './useForceUpdate';
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,43 @@ function useAutoUpdateLayoutRefState(state, callback) {
174
174
  clearInterval(tm);
175
175
  };
176
176
  }, [interval]);
177
- }function useForceUpdate() {
178
- var _a = useState(0), setValue = _a[1];
179
- return useCallback(function () {
180
- setValue(function (old) { return old + 1; });
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 clearIntervalRef(ref) {
198
+ if (ref.current) {
199
+ clearInterval(ref.current);
200
+ ref.current = undefined;
201
+ }
202
+ }function useIntervalRef() {
203
+ var ref = useRef();
204
+ useEffect(function () {
205
+ return function () {
206
+ clearIntervalRef(ref);
207
+ };
208
+ }, []);
209
+ var setIntervalFunc = useCallback(function (callback, ms) {
210
+ clearIntervalRef(ref);
211
+ ref.current = setInterval(function () {
212
+ callback(ref);
213
+ }, ms);
181
214
  }, []);
182
- }export{useAutoForceUpdate,useAutoUpdateLayoutRef,useAutoUpdateLayoutRefState,useAutoUpdateLayoutState,useAutoUpdateRef,useAutoUpdateRefState,useAutoUpdateState,useFirstSkipEffect,useFirstSkipLayoutEffect,useForceUpdate,useForwardRef,useLayoutPerformance,usePerformance};
215
+ return [ref, setIntervalFunc];
216
+ }export{clearIntervalRef,clearTimeoutRef,useAutoForceUpdate,useAutoUpdateLayoutRef,useAutoUpdateLayoutRefState,useAutoUpdateLayoutState,useAutoUpdateRef,useAutoUpdateRefState,useAutoUpdateState,useFirstSkipEffect,useFirstSkipLayoutEffect,useForwardRef,useIntervalRef,useLayoutPerformance,usePerformance,useTimeoutRef};
package/dist/index.js CHANGED
@@ -174,9 +174,43 @@ function useAutoUpdateLayoutRefState(state, callback) {
174
174
  clearInterval(tm);
175
175
  };
176
176
  }, [interval]);
177
- }function useForceUpdate() {
178
- var _a = react.useState(0), setValue = _a[1];
179
- return react.useCallback(function () {
180
- setValue(function (old) { return old + 1; });
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 clearIntervalRef(ref) {
198
+ if (ref.current) {
199
+ clearInterval(ref.current);
200
+ ref.current = undefined;
201
+ }
202
+ }function useIntervalRef() {
203
+ var ref = react.useRef();
204
+ react.useEffect(function () {
205
+ return function () {
206
+ clearIntervalRef(ref);
207
+ };
208
+ }, []);
209
+ var setIntervalFunc = react.useCallback(function (callback, ms) {
210
+ clearIntervalRef(ref);
211
+ ref.current = setInterval(function () {
212
+ callback(ref);
213
+ }, ms);
181
214
  }, []);
182
- }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.useLayoutPerformance=useLayoutPerformance;exports.usePerformance=usePerformance;
215
+ return [ref, setIntervalFunc];
216
+ }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.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useLayoutPerformance=useLayoutPerformance;exports.usePerformance=usePerformance;exports.useTimeoutRef=useTimeoutRef;
@@ -1 +1,2 @@
1
- export default function useAutoForceUpdate(name: string, interval: number): void;
1
+ export declare function useAutoForceUpdate(name: string, interval: number): void;
2
+ export default useAutoForceUpdate;
@@ -1,2 +1,3 @@
1
1
  import { MutableRefObject } from 'react';
2
- export default function useAutoUpdateLayoutRef<T>(value: T): MutableRefObject<T>;
2
+ export declare function useAutoUpdateLayoutRef<T>(value: T): MutableRefObject<T>;
3
+ export default useAutoUpdateLayoutRef;
@@ -1,8 +1,9 @@
1
1
  import { MutableRefObject, SetStateAction } from 'react';
2
- export default function useAutoUpdateLayoutRefState<T>(state: Exclude<T, (...args: any[]) => any>): [MutableRefObject<T>, T, (value: SetStateAction<T>) => T];
3
- export default function useAutoUpdateLayoutRefState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [MutableRefObject<T>, T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
4
- export default function useAutoUpdateLayoutRefState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
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 default function useAutoUpdateLayoutState<T>(state: Exclude<T, (...args: any[]) => any>): [T, (value: SetStateAction<T>) => T];
3
- export default function useAutoUpdateLayoutState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
4
- export default function useAutoUpdateLayoutState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
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,2 +1,3 @@
1
1
  import { MutableRefObject } from 'react';
2
- export default function useAutoUpdateRef<T>(value: T): MutableRefObject<T>;
2
+ export declare function useAutoUpdateRef<T>(value: T): MutableRefObject<T>;
3
+ export default useAutoUpdateRef;
@@ -1,8 +1,9 @@
1
1
  import { MutableRefObject, SetStateAction } from 'react';
2
- export default function useAutoUpdateRefState<T>(state: Exclude<T, (...args: any[]) => any>): [MutableRefObject<T>, T, (value: SetStateAction<T>) => T];
3
- export default function useAutoUpdateRefState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [MutableRefObject<T>, T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
4
- export default function useAutoUpdateRefState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
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 default function useAutoUpdateState<T>(state: Exclude<T, (...args: any[]) => any>): [T, (value: SetStateAction<T>) => T];
3
- export default function useAutoUpdateState<T>(state: Exclude<T, (...args: any[]) => any>, callback: (state: T) => T): [T, (value: SetStateAction<T>, skipCallback?: boolean) => T];
4
- export default function useAutoUpdateState<T = never, StateT = never>(state: Exclude<StateT, (...args: any[]) => any>, callback: (state: T | StateT) => T extends never ? StateT : T): [
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 default function useFirstSkipEffect(effect: EffectCallback, deps?: DependencyList): void;
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 default function useFirstSkipLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
2
+ export declare function useFirstSkipLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
3
+ export default useFirstSkipLayoutEffect;
@@ -1 +1 @@
1
- export default function useForceUpdate(): () => void;
1
+ export default function useForceUpdate(delay?: number): () => void;
@@ -1,2 +1,3 @@
1
1
  import { ForwardedRef } from 'react';
2
- export default function useForwardRef<T>(ref: ForwardedRef<T>, value: T): void;
2
+ export declare function useForwardRef<T>(ref: ForwardedRef<T>, value: T): void;
3
+ export default useForwardRef;
@@ -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 default function useLayoutPerformance(name: string): void;
1
+ export declare function useLayoutPerformance(name: string): void;
2
+ export default useLayoutPerformance;
@@ -1 +1,2 @@
1
- export default function usePerformance(name: string): void;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pdg/react-hook",
3
3
  "title": "React Hook",
4
- "version": "1.0.21",
4
+ "version": "1.0.23",
5
5
  "description": "React Hook",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
@@ -40,8 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "@pdg/util": "^1.0.22",
42
42
  "@types/react": "^17.0.0 || ^18.0.0",
43
- "react": "^17.0.0 || ^18.0.0",
44
- "react-dom": "^17.0.0 || ^18.0.0"
43
+ "react": "^17.0.0 || ^18.0.0"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@rollup/plugin-commonjs": "^25.0.7",