@monkvision/common 5.1.3 → 5.1.4

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/README/HOOKS.md CHANGED
@@ -265,6 +265,19 @@ This hook returns takes a `ResponsiveStyleProperties` declarations object (see t
265
265
  `@monkvision/types` package for more details) containing a media query and returns either the CSSProperties contained in
266
266
  the type, or `null` if the query conditions are not met. Note that if there are no query, the style will be applied.
267
267
 
268
+
269
+ ### useSafeTimeout
270
+ ```tsx
271
+ import { sights } from '@monkvision/sights';
272
+ import { useSafeTimeout } from '@monkvision/common';
273
+
274
+ function TestComponent() {
275
+ const setSafeTimeout = useSafeTimeout();
276
+ setSafeTimeout(() => console.log('test'), 1000);
277
+ }
278
+ ```
279
+ Custom hook that provides a safe way to use setTimeout.
280
+
268
281
  ### useSearchParams
269
282
  ```tsx
270
283
  import { sights } from '@monkvision/sights';
@@ -13,3 +13,4 @@ export * from './useObjectMemo';
13
13
  export * from './useForm';
14
14
  export * from './useIsMounted';
15
15
  export * from './useDeviceOrientation';
16
+ export * from './useSafeTimeout';
@@ -29,3 +29,4 @@ __exportStar(require("./useObjectMemo"), exports);
29
29
  __exportStar(require("./useForm"), exports);
30
30
  __exportStar(require("./useIsMounted"), exports);
31
31
  __exportStar(require("./useDeviceOrientation"), exports);
32
+ __exportStar(require("./useSafeTimeout"), exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * A custom hook that provides a safe way to use setTimeout.
3
+ */
4
+ export declare function useSafeTimeout(): (callback: () => void, delay: number) => void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSafeTimeout = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * A custom hook that provides a safe way to use setTimeout.
7
+ */
8
+ function useSafeTimeout() {
9
+ var isMounted = (0, react_1.useRef)(true);
10
+ var timeoutRef = (0, react_1.useRef)(null);
11
+ (0, react_1.useEffect)(function () {
12
+ return function () {
13
+ isMounted.current = false;
14
+ if (timeoutRef.current) {
15
+ clearTimeout(timeoutRef.current);
16
+ }
17
+ };
18
+ }, []);
19
+ return (0, react_1.useCallback)(function (callback, delay) {
20
+ timeoutRef.current = setTimeout(function () {
21
+ if (isMounted.current) {
22
+ callback();
23
+ }
24
+ }, delay);
25
+ }, []);
26
+ }
27
+ exports.useSafeTimeout = useSafeTimeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/common",
3
- "version": "5.1.3",
3
+ "version": "5.1.4",
4
4
  "license": "BSD-3-Clause-Clear",
5
5
  "packageManager": "yarn@3.2.4",
6
6
  "description": "MonkJs common logic package",
@@ -28,10 +28,10 @@
28
28
  "lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
29
29
  },
30
30
  "dependencies": {
31
- "@monkvision/analytics": "5.1.3",
32
- "@monkvision/monitoring": "5.1.3",
33
- "@monkvision/sights": "5.1.3",
34
- "@monkvision/types": "5.1.3",
31
+ "@monkvision/analytics": "5.1.4",
32
+ "@monkvision/monitoring": "5.1.4",
33
+ "@monkvision/sights": "5.1.4",
34
+ "@monkvision/types": "5.1.4",
35
35
  "i18next": "^23.4.5",
36
36
  "jsonwebtoken": "^9.0.2",
37
37
  "jwt-decode": "^4.0.0",
@@ -47,13 +47,13 @@
47
47
  "react-router-dom": "^6.22.3"
48
48
  },
49
49
  "devDependencies": {
50
- "@monkvision/eslint-config-base": "5.1.3",
51
- "@monkvision/eslint-config-typescript": "5.1.3",
52
- "@monkvision/eslint-config-typescript-react": "5.1.3",
53
- "@monkvision/jest-config": "5.1.3",
54
- "@monkvision/prettier-config": "5.1.3",
55
- "@monkvision/test-utils": "5.1.3",
56
- "@monkvision/typescript-config": "5.1.3",
50
+ "@monkvision/eslint-config-base": "5.1.4",
51
+ "@monkvision/eslint-config-typescript": "5.1.4",
52
+ "@monkvision/eslint-config-typescript-react": "5.1.4",
53
+ "@monkvision/jest-config": "5.1.4",
54
+ "@monkvision/prettier-config": "5.1.4",
55
+ "@monkvision/test-utils": "5.1.4",
56
+ "@monkvision/typescript-config": "5.1.4",
57
57
  "@testing-library/react": "^12.1.5",
58
58
  "@testing-library/react-hooks": "^8.0.1",
59
59
  "@types/jest": "^29.2.2",
@@ -96,5 +96,5 @@
96
96
  "url": "https://github.com/monkvision/monkjs/issues"
97
97
  },
98
98
  "homepage": "https://github.com/monkvision/monkjs",
99
- "gitHead": "fc9a46364b6b20374800fad854057ef7d3b28c39"
99
+ "gitHead": "d6235358964c496cecbe3932fc00b03ac69e79eb"
100
100
  }