@siberiacancode/reactuse 0.2.13 → 0.2.14
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/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs +1 -1
- package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
- package/dist/cjs/utils/helpers/debounce.cjs +1 -1
- package/dist/cjs/utils/helpers/debounce.cjs.map +1 -1
- package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs +14 -7
- package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
- package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
- package/dist/esm/utils/helpers/debounce.mjs +6 -5
- package/dist/esm/utils/helpers/debounce.mjs.map +1 -1
- package/dist/types/hooks/useDebounceCallback/useDebounceCallback.d.ts +4 -1
- package/dist/types/hooks/useLatest/useLatest.d.ts +1 -1
- package/dist/types/utils/helpers/debounce.d.ts +5 -1
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),a=(n,t)=>{const r=c.useRef(n),e=c.useRef(null),u=c.useRef(t);return r.current=n,u.current=t,c.useMemo(()=>{const o=()=>{e.current&&(clearTimeout(e.current),e.current=void 0)},s=function(...l){o(),e.current=setTimeout(()=>{r.current.apply(this,l)},u.current)};return s.cancel=o,s},[])};exports.useDebounceCallback=a;
|
|
2
2
|
//# sourceMappingURL=useDebounceCallback.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounceCallback.cjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo } from 'react';\n\
|
|
1
|
+
{"version":3,"file":"useDebounceCallback.cjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useDebounceCallback\n * @description - Hook that creates a debounced callback\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with debounce\n *\n * @example\n * const debouncedCallback = useDebounceCallback(() => console.log('callback'), 500);\n */\nexport const useDebounceCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): DebouncedCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const delayRef = useRef(delay);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const debounced = useMemo(() => {\n const cancel = () => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = undefined as any;\n }\n };\n\n const debouncedCallback = function (this: any, ...args: Params) {\n cancel();\n timerRef.current = setTimeout(() => {\n internalCallbackRef.current.apply(this, args);\n }, delayRef.current);\n };\n\n debouncedCallback.cancel = cancel;\n\n return debouncedCallback;\n }, []);\n\n return debounced;\n};\n"],"names":["useDebounceCallback","callback","delay","internalCallbackRef","useRef","timerRef","delayRef","useMemo","cancel","debouncedCallback","args"],"mappings":"yGAoBaA,EAAsB,CACjCC,EACAC,IAC8B,CAC9B,MAAMC,EAAsBC,EAAAA,OAAOH,CAAQ,EACrCI,EAAWD,EAAAA,OAA6C,IAAI,EAC5DE,EAAWF,EAAAA,OAAOF,CAAK,EAE7B,OAAAC,EAAoB,QAAUF,EAC9BK,EAAS,QAAUJ,EAEDK,EAAAA,QAAQ,IAAM,CAC9B,MAAMC,EAAS,IAAM,CACfH,EAAS,UACX,aAAaA,EAAS,OAAO,EAC7BA,EAAS,QAAU,OACrB,EAGII,EAAoB,YAAwBC,EAAc,CAC9DF,EAAA,EACAH,EAAS,QAAU,WAAW,IAAM,CAClCF,EAAoB,QAAQ,MAAM,KAAMO,CAAI,CAAA,EAC3CJ,EAAS,OAAO,CAAA,EAGrB,OAAAG,EAAkB,OAASD,EAEpBC,CAAA,EACN,EAAE,CAGP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLatest.cjs","sources":["../../../../src/hooks/useLatest/useLatest.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nimport { useMemo, useRef } from 'react';\n\nexport interface UseLatestReturn<Value> {\n ref: RefObject<Value>;\n value: Value;\n}\n\n/**\n * @name useLatest\n * @description - Hook that returns the stable reference of the value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @returns {UseLatestReturn<Value>} The previous value\n *\n * @example\n * const
|
|
1
|
+
{"version":3,"file":"useLatest.cjs","sources":["../../../../src/hooks/useLatest/useLatest.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nimport { useMemo, useRef } from 'react';\n\nexport interface UseLatestReturn<Value> {\n ref: RefObject<Value>;\n value: Value;\n}\n\n/**\n * @name useLatest\n * @description - Hook that returns the stable reference of the value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @returns {UseLatestReturn<Value>} The previous value\n *\n * @example\n * const { value, ref } = useLatest(value);\n */\nexport const useLatest = <Value>(value: Value): UseLatestReturn<Value> => {\n const valueRef = useRef<Value>(value);\n valueRef.current = value;\n return useMemo(\n () => ({\n get value() {\n return valueRef.current;\n },\n ref: valueRef\n }),\n []\n );\n};\n"],"names":["useLatest","value","valueRef","useRef","useMemo"],"mappings":"yGAqBaA,EAAoBC,GAAyC,CACxE,MAAMC,EAAWC,EAAAA,OAAcF,CAAK,EACpC,OAAAC,EAAS,QAAUD,EACZG,EAAAA,QACL,KAAO,CACL,IAAI,OAAQ,CACV,OAAOF,EAAS,OAAA,EAElB,IAAKA,CAAA,GAEP,CAAA,CAAC,CAEL"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(n,o)=>{let e;const t=()=>clearTimeout(e),c=function(...u){t(),e=setTimeout(()=>n.apply(this,u),o)};return c.cancel=t,c};exports.debounce=i;
|
|
2
2
|
//# sourceMappingURL=debounce.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.cjs","sources":["../../../../src/utils/helpers/debounce.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"debounce.cjs","sources":["../../../../src/utils/helpers/debounce.ts"],"sourcesContent":["type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\nexport const debounce = <Params extends unknown[]>(\n callback: (...args: Params) => void,\n delay: number\n): DebouncedCallback<Params> => {\n let timer: ReturnType<typeof setTimeout>;\n\n const cancel = () => clearTimeout(timer);\n\n const debounced = function (this: any, ...args: Params) {\n cancel();\n timer = setTimeout(() => callback.apply(this, args), delay);\n };\n\n debounced.cancel = cancel;\n\n return debounced;\n};\n"],"names":["debounce","callback","delay","timer","cancel","debounced","args"],"mappings":"gFAIO,MAAMA,EAAW,CACtBC,EACAC,IAC8B,CAC9B,IAAIC,EAEJ,MAAMC,EAAS,IAAM,aAAaD,CAAK,EAEjCE,EAAY,YAAwBC,EAAc,CACtDF,EAAA,EACAD,EAAQ,WAAW,IAAMF,EAAS,MAAM,KAAMK,CAAI,EAAGJ,CAAK,CAAA,EAG5D,OAAAG,EAAU,OAASD,EAEZC,CACT"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { useRef as n, useMemo as a } from "react";
|
|
2
|
+
const f = (c, r) => {
|
|
3
|
+
const t = n(c), e = n(null), u = n(r);
|
|
4
|
+
return t.current = c, u.current = r, a(() => {
|
|
5
|
+
const o = () => {
|
|
6
|
+
e.current && (clearTimeout(e.current), e.current = void 0);
|
|
7
|
+
}, s = function(...l) {
|
|
8
|
+
o(), e.current = setTimeout(() => {
|
|
9
|
+
t.current.apply(this, l);
|
|
10
|
+
}, u.current);
|
|
11
|
+
};
|
|
12
|
+
return s.cancel = o, s;
|
|
13
|
+
}, []);
|
|
7
14
|
};
|
|
8
15
|
export {
|
|
9
|
-
|
|
16
|
+
f as useDebounceCallback
|
|
10
17
|
};
|
|
11
18
|
//# sourceMappingURL=useDebounceCallback.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounceCallback.mjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo } from 'react';\n\
|
|
1
|
+
{"version":3,"file":"useDebounceCallback.mjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useDebounceCallback\n * @description - Hook that creates a debounced callback\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with debounce\n *\n * @example\n * const debouncedCallback = useDebounceCallback(() => console.log('callback'), 500);\n */\nexport const useDebounceCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): DebouncedCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const delayRef = useRef(delay);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const debounced = useMemo(() => {\n const cancel = () => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = undefined as any;\n }\n };\n\n const debouncedCallback = function (this: any, ...args: Params) {\n cancel();\n timerRef.current = setTimeout(() => {\n internalCallbackRef.current.apply(this, args);\n }, delayRef.current);\n };\n\n debouncedCallback.cancel = cancel;\n\n return debouncedCallback;\n }, []);\n\n return debounced;\n};\n"],"names":["useDebounceCallback","callback","delay","internalCallbackRef","useRef","timerRef","delayRef","useMemo","cancel","debouncedCallback","args"],"mappings":";AAoBO,MAAMA,IAAsB,CACjCC,GACAC,MAC8B;AAC9B,QAAMC,IAAsBC,EAAOH,CAAQ,GACrCI,IAAWD,EAA6C,IAAI,GAC5DE,IAAWF,EAAOF,CAAK;AAE7B,SAAAC,EAAoB,UAAUF,GAC9BK,EAAS,UAAUJ,GAEDK,EAAQ,MAAM;AAC9B,UAAMC,IAAS,MAAM;AACnB,MAAIH,EAAS,YACX,aAAaA,EAAS,OAAO,GAC7BA,EAAS,UAAU;AAAA,IACrB,GAGII,IAAoB,YAAwBC,GAAc;AAC9D,MAAAF,EAAA,GACAH,EAAS,UAAU,WAAW,MAAM;AAClC,QAAAF,EAAoB,QAAQ,MAAM,MAAMO,CAAI;AAAA,MAAA,GAC3CJ,EAAS,OAAO;AAAA,IAAA;AAGrB,WAAAG,EAAkB,SAASD,GAEpBC;AAAA,EAAA,GACN,EAAE;AAGP;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLatest.mjs","sources":["../../../../src/hooks/useLatest/useLatest.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nimport { useMemo, useRef } from 'react';\n\nexport interface UseLatestReturn<Value> {\n ref: RefObject<Value>;\n value: Value;\n}\n\n/**\n * @name useLatest\n * @description - Hook that returns the stable reference of the value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @returns {UseLatestReturn<Value>} The previous value\n *\n * @example\n * const
|
|
1
|
+
{"version":3,"file":"useLatest.mjs","sources":["../../../../src/hooks/useLatest/useLatest.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nimport { useMemo, useRef } from 'react';\n\nexport interface UseLatestReturn<Value> {\n ref: RefObject<Value>;\n value: Value;\n}\n\n/**\n * @name useLatest\n * @description - Hook that returns the stable reference of the value\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value} value The value to get the previous value\n * @returns {UseLatestReturn<Value>} The previous value\n *\n * @example\n * const { value, ref } = useLatest(value);\n */\nexport const useLatest = <Value>(value: Value): UseLatestReturn<Value> => {\n const valueRef = useRef<Value>(value);\n valueRef.current = value;\n return useMemo(\n () => ({\n get value() {\n return valueRef.current;\n },\n ref: valueRef\n }),\n []\n );\n};\n"],"names":["useLatest","value","valueRef","useRef","useMemo"],"mappings":";AAqBO,MAAMA,IAAY,CAAQC,MAAyC;AACxE,QAAMC,IAAWC,EAAcF,CAAK;AACpC,SAAAC,EAAS,UAAUD,GACZG;AAAA,IACL,OAAO;AAAA,MACL,IAAI,QAAQ;AACV,eAAOF,EAAS;AAAA,MAAA;AAAA,MAElB,KAAKA;AAAA,IAAA;AAAA,IAEP,CAAA;AAAA,EAAC;AAEL;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const i = (n, o) => {
|
|
2
2
|
let e;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const t = () => clearTimeout(e), c = function(...u) {
|
|
4
|
+
t(), e = setTimeout(() => n.apply(this, u), o);
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
return c.cancel = t, c;
|
|
7
|
+
};
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
+
i as debounce
|
|
9
10
|
};
|
|
10
11
|
//# sourceMappingURL=debounce.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.mjs","sources":["../../../../src/utils/helpers/debounce.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"debounce.mjs","sources":["../../../../src/utils/helpers/debounce.ts"],"sourcesContent":["type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\nexport const debounce = <Params extends unknown[]>(\n callback: (...args: Params) => void,\n delay: number\n): DebouncedCallback<Params> => {\n let timer: ReturnType<typeof setTimeout>;\n\n const cancel = () => clearTimeout(timer);\n\n const debounced = function (this: any, ...args: Params) {\n cancel();\n timer = setTimeout(() => callback.apply(this, args), delay);\n };\n\n debounced.cancel = cancel;\n\n return debounced;\n};\n"],"names":["debounce","callback","delay","timer","cancel","debounced","args"],"mappings":"AAIO,MAAMA,IAAW,CACtBC,GACAC,MAC8B;AAC9B,MAAIC;AAEJ,QAAMC,IAAS,MAAM,aAAaD,CAAK,GAEjCE,IAAY,YAAwBC,GAAc;AACtD,IAAAF,EAAA,GACAD,IAAQ,WAAW,MAAMF,EAAS,MAAM,MAAMK,CAAI,GAAGJ,CAAK;AAAA,EAAA;AAG5D,SAAAG,EAAU,SAASD,GAEZC;AACT;"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {
|
|
2
|
+
cancel: () => void;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* @name useDebounceCallback
|
|
3
6
|
* @description - Hook that creates a debounced callback
|
|
@@ -12,4 +15,4 @@
|
|
|
12
15
|
* @example
|
|
13
16
|
* const debouncedCallback = useDebounceCallback(() => console.log('callback'), 500);
|
|
14
17
|
*/
|
|
15
|
-
export declare const useDebounceCallback: <Params extends unknown[], Return>(callback: (...args: Params) => Return, delay: number) =>
|
|
18
|
+
export declare const useDebounceCallback: <Params extends unknown[], Return>(callback: (...args: Params) => Return, delay: number) => DebouncedCallback<Params>;
|
|
@@ -13,6 +13,6 @@ export interface UseLatestReturn<Value> {
|
|
|
13
13
|
* @returns {UseLatestReturn<Value>} The previous value
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
|
-
* const
|
|
16
|
+
* const { value, ref } = useLatest(value);
|
|
17
17
|
*/
|
|
18
18
|
export declare const useLatest: <Value>(value: Value) => UseLatestReturn<Value>;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {
|
|
2
|
+
cancel: () => void;
|
|
3
|
+
};
|
|
4
|
+
export declare const debounce: <Params extends unknown[]>(callback: (...args: Params) => void, delay: number) => DebouncedCallback<Params>;
|
|
5
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "The ultimate collection of react hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"lint-staged": "lint-staged"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@types/react": "^18",
|
|
54
|
+
"@types/react": "^17 || ^18 || ^19",
|
|
55
55
|
"react": "^17 || ^18 || ^19",
|
|
56
56
|
"react-dom": "^17 || ^18 || ^19"
|
|
57
57
|
},
|