@ts-hooks-kit/core 0.1.0 → 0.2.0
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/index.cjs +22 -22
- package/dist/index.js +22 -22
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -560,6 +560,28 @@ function useDarkMode(options = {}) {
|
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region src/useUnmount/useUnmount.ts
|
|
565
|
+
/**
|
|
566
|
+
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
567
|
+
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
568
|
+
* @public
|
|
569
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
570
|
+
* @example
|
|
571
|
+
* ```tsx
|
|
572
|
+
* useUnmount(() => {
|
|
573
|
+
* // Cleanup logic here
|
|
574
|
+
* });
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
function useUnmount(func) {
|
|
578
|
+
const funcRef = (0, react.useRef)(func);
|
|
579
|
+
funcRef.current = func;
|
|
580
|
+
(0, react.useEffect)(() => () => {
|
|
581
|
+
funcRef.current();
|
|
582
|
+
}, []);
|
|
583
|
+
}
|
|
584
|
+
|
|
563
585
|
//#endregion
|
|
564
586
|
//#region src/utils/debounce.ts
|
|
565
587
|
/**
|
|
@@ -657,28 +679,6 @@ function debounce(func, delay, options = {}) {
|
|
|
657
679
|
return debounced;
|
|
658
680
|
}
|
|
659
681
|
|
|
660
|
-
//#endregion
|
|
661
|
-
//#region src/useUnmount/useUnmount.ts
|
|
662
|
-
/**
|
|
663
|
-
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
664
|
-
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
665
|
-
* @public
|
|
666
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
667
|
-
* @example
|
|
668
|
-
* ```tsx
|
|
669
|
-
* useUnmount(() => {
|
|
670
|
-
* // Cleanup logic here
|
|
671
|
-
* });
|
|
672
|
-
* ```
|
|
673
|
-
*/
|
|
674
|
-
function useUnmount(func) {
|
|
675
|
-
const funcRef = (0, react.useRef)(func);
|
|
676
|
-
funcRef.current = func;
|
|
677
|
-
(0, react.useEffect)(() => () => {
|
|
678
|
-
funcRef.current();
|
|
679
|
-
}, []);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
682
|
//#endregion
|
|
683
683
|
//#region src/useDebounceCallback/useDebounceCallback.ts
|
|
684
684
|
/**
|
package/dist/index.js
CHANGED
|
@@ -536,6 +536,28 @@ function useDarkMode(options = {}) {
|
|
|
536
536
|
};
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/useUnmount/useUnmount.ts
|
|
541
|
+
/**
|
|
542
|
+
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
543
|
+
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
544
|
+
* @public
|
|
545
|
+
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
546
|
+
* @example
|
|
547
|
+
* ```tsx
|
|
548
|
+
* useUnmount(() => {
|
|
549
|
+
* // Cleanup logic here
|
|
550
|
+
* });
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
function useUnmount(func) {
|
|
554
|
+
const funcRef = useRef(func);
|
|
555
|
+
funcRef.current = func;
|
|
556
|
+
useEffect(() => () => {
|
|
557
|
+
funcRef.current();
|
|
558
|
+
}, []);
|
|
559
|
+
}
|
|
560
|
+
|
|
539
561
|
//#endregion
|
|
540
562
|
//#region src/utils/debounce.ts
|
|
541
563
|
/**
|
|
@@ -633,28 +655,6 @@ function debounce(func, delay, options = {}) {
|
|
|
633
655
|
return debounced;
|
|
634
656
|
}
|
|
635
657
|
|
|
636
|
-
//#endregion
|
|
637
|
-
//#region src/useUnmount/useUnmount.ts
|
|
638
|
-
/**
|
|
639
|
-
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
640
|
-
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
641
|
-
* @public
|
|
642
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
643
|
-
* @example
|
|
644
|
-
* ```tsx
|
|
645
|
-
* useUnmount(() => {
|
|
646
|
-
* // Cleanup logic here
|
|
647
|
-
* });
|
|
648
|
-
* ```
|
|
649
|
-
*/
|
|
650
|
-
function useUnmount(func) {
|
|
651
|
-
const funcRef = useRef(func);
|
|
652
|
-
funcRef.current = func;
|
|
653
|
-
useEffect(() => () => {
|
|
654
|
-
funcRef.current();
|
|
655
|
-
}, []);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
658
|
//#endregion
|
|
659
659
|
//#region src/useDebounceCallback/useDebounceCallback.ts
|
|
660
660
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-hooks-kit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React hook library based on usehooks-ts, upgraded for React 19 compatibility.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@types/node": "^24.3.0",
|
|
57
57
|
"@types/react": "^19.1.11",
|
|
58
58
|
"@types/react-dom": "^19.1.7",
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
59
60
|
"jsdom": "^26.1.0",
|
|
60
61
|
"react": "^19.2.0",
|
|
61
62
|
"react-dom": "^19.2.0",
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
"build": "tsdown",
|
|
72
73
|
"dev": "tsdown --watch",
|
|
73
74
|
"test": "vitest run",
|
|
75
|
+
"test:coverage": "vitest run --coverage",
|
|
74
76
|
"test:watch": "vitest",
|
|
75
77
|
"lint": "tsc --noEmit",
|
|
76
78
|
"clean": "rimraf dist coverage .turbo *.tsbuildinfo"
|