@aiszlab/relax 1.2.66 → 1.2.68

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,8 @@
1
+ /**
2
+ * @description
3
+ * use timer
4
+ */
5
+ export declare const useTimer: () => {
6
+ timeout: (handler: VoidFunction, duration?: number) => void;
7
+ clear: () => void;
8
+ };
@@ -0,0 +1,32 @@
1
+ import { useRef, useCallback } from 'react';
2
+ import { useUnmount } from './use-unmount.js';
3
+
4
+ /**
5
+ * @description
6
+ * use timer
7
+ */
8
+ var useTimer = function useTimer() {
9
+ var timed = useRef(void 0);
10
+ var clear = useCallback(function () {
11
+ clearTimeout(timed.current);
12
+ timed.current = void 0;
13
+ }, []);
14
+ var timeout = useCallback(function (handler) {
15
+ var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
16
+ clear();
17
+ if (duration <= 0) {
18
+ handler();
19
+ return;
20
+ }
21
+ timed.current = setTimeout(function () {
22
+ handler();
23
+ }, duration);
24
+ }, []);
25
+ useUnmount(clear);
26
+ return {
27
+ timeout: timeout,
28
+ clear: clear
29
+ };
30
+ };
31
+
32
+ export { useTimer };
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export { useIdentity } from "./hooks/use-identity";
29
29
  export { useMediaQuery } from "./hooks/use-media-query";
30
30
  export { useClickAway } from "./hooks/use-click-away";
31
31
  export { useUnmount } from "./hooks/use-unmount";
32
+ export { useTimer } from "./hooks/use-timer";
32
33
  /**
33
34
  * @description
34
35
  * is
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ export { useIdentity } from './hooks/use-identity.js';
25
25
  export { useMediaQuery } from './hooks/use-media-query.js';
26
26
  export { useClickAway } from './hooks/use-click-away.js';
27
27
  export { useUnmount } from './hooks/use-unmount.js';
28
+ export { useTimer } from './hooks/use-timer.js';
28
29
  export { isRefable } from './is/is-refable.js';
29
30
  export { isUndefined } from './is/is-undefined.js';
30
31
  export { isStateGetter } from './is/is-state-getter.js';
@@ -4,7 +4,7 @@
4
4
  */
5
5
  var isDomUsable = function isDomUsable() {
6
6
  var _window$document;
7
- return typeof window === "undefined" || !((_window$document = window.document) !== null && _window$document !== void 0 && _window$document.createElement);
7
+ return typeof window !== "undefined" && !!((_window$document = window.document) !== null && _window$document !== void 0 && _window$document.createElement);
8
8
  };
9
9
 
10
10
  export { isDomUsable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.66",
3
+ "version": "1.2.68",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {