@1hook/use-debounce-fn 0.0.4-beta-0 → 0.0.5

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.d.ts CHANGED
@@ -15,6 +15,6 @@ type UseDebounceFnReturn = {
15
15
  */
16
16
  isPending: boolean;
17
17
  };
18
- declare function useDebounceFn(defaultDelay?: number): UseDebounceFnReturn;
18
+ declare function useDebounceFn(defaultDelay: number): UseDebounceFnReturn;
19
19
 
20
20
  export { type UseDebounceFnReturn, useDebounceFn };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  // src/index.ts
4
- function useDebounceFn(defaultDelay = 0) {
4
+ function useDebounceFn(defaultDelay) {
5
5
  const timeoutRef = React.useRef(0);
6
6
  const [isPending, setIsPending] = React.useState(false);
7
7
  const cancel = React.useCallback(() => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAoBO,SAAS,aAAA,CAAc,eAAuB,CAAwB,EAAA;AAC3E,EAAM,MAAA,UAAA,GAAa,KAAM,CAAA,MAAA,CAAgC,CAAC,CAAA;AAG1D,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,KAAK,CAAA;AAEtD,EAAM,MAAA,MAAA,GAAS,KAAM,CAAA,WAAA,CAAY,MAAM;AACrC,IAAA,YAAA,CAAa,KAAK,CAAA;AAClB,IAAA,YAAA,CAAa,WAAW,OAAO,CAAA;AAAA,GACjC,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,WAAW,KAAM,CAAA,WAAA;AAAA,IACrB,CAAC,EAAe,EAAA,KAAA,GAAgB,YAAiB,KAAA;AAC/C,MAAO,MAAA,EAAA;AACP,MAAA,IAAI,CAAC,KAAO,EAAA;AACV,QAAG,EAAA,EAAA;AACH,QAAA;AAAA;AAEF,MAAA,YAAA,CAAa,IAAI,CAAA;AACjB,MAAW,UAAA,CAAA,OAAA,GAAU,WAAW,MAAM;AACpC,QAAA,YAAA,CAAa,KAAK,CAAA;AAClB,QAAG,EAAA,EAAA;AAAA,SACF,KAAK,CAAA;AAAA,KACV;AAAA,IACA,CAAC,QAAQ,YAAY;AAAA,GACvB;AAGA,EAAA,KAAA,CAAM,SAAU,CAAA,MAAM,MAAQ,EAAA,CAAC,MAAM,CAAC,CAAA;AAEtC,EAAO,OAAA,EAAE,QAAU,EAAA,MAAA,EAAQ,SAAU,EAAA;AACvC","file":"index.js","sourcesContent":["import React from 'react'\n\nexport type UseDebounceFnReturn = {\n /**\n * Debounce a function execution.\n *\n * @param fn - The function to debounce.\n * @param delay - Override the default delay in milliseconds (optional).\n */\n debounce: (fn: () => any, delay?: number) => void\n /**\n * Cancel the debounce.\n */\n cancel: () => void\n /**\n * Whether a debounced call is pending.\n */\n isPending: boolean\n}\n\nexport function useDebounceFn(defaultDelay: number = 0): UseDebounceFnReturn {\n const timeoutRef = React.useRef<NodeJS.Timeout | number>(0)\n\n // use async transitions in React 19\n const [isPending, setIsPending] = React.useState(false)\n\n const cancel = React.useCallback(() => {\n setIsPending(false)\n clearTimeout(timeoutRef.current)\n }, [])\n\n const debounce = React.useCallback(\n (fn: () => any, delay: number = defaultDelay) => {\n cancel()\n if (!delay) {\n fn()\n return\n }\n setIsPending(true)\n timeoutRef.current = setTimeout(() => {\n setIsPending(false)\n fn()\n }, delay)\n },\n [cancel, defaultDelay],\n )\n\n // clear the debounce on unmount\n React.useEffect(() => cancel, [cancel])\n\n return { debounce, cancel, isPending }\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAoBO,SAAS,cAAc,YAA2C,EAAA;AACvE,EAAM,MAAA,UAAA,GAAa,KAAM,CAAA,MAAA,CAAgC,CAAC,CAAA;AAG1D,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,KAAK,CAAA;AAEtD,EAAM,MAAA,MAAA,GAAS,KAAM,CAAA,WAAA,CAAY,MAAM;AACrC,IAAA,YAAA,CAAa,KAAK,CAAA;AAClB,IAAA,YAAA,CAAa,WAAW,OAAO,CAAA;AAAA,GACjC,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,WAAW,KAAM,CAAA,WAAA;AAAA,IACrB,CAAC,EAAe,EAAA,KAAA,GAAgB,YAAiB,KAAA;AAC/C,MAAO,MAAA,EAAA;AACP,MAAA,IAAI,CAAC,KAAO,EAAA;AACV,QAAG,EAAA,EAAA;AACH,QAAA;AAAA;AAEF,MAAA,YAAA,CAAa,IAAI,CAAA;AACjB,MAAW,UAAA,CAAA,OAAA,GAAU,WAAW,MAAM;AACpC,QAAA,YAAA,CAAa,KAAK,CAAA;AAClB,QAAG,EAAA,EAAA;AAAA,SACF,KAAK,CAAA;AAAA,KACV;AAAA,IACA,CAAC,QAAQ,YAAY;AAAA,GACvB;AAGA,EAAA,KAAA,CAAM,SAAU,CAAA,MAAM,MAAQ,EAAA,CAAC,MAAM,CAAC,CAAA;AAEtC,EAAO,OAAA,EAAE,QAAU,EAAA,MAAA,EAAQ,SAAU,EAAA;AACvC","file":"index.js","sourcesContent":["import React from 'react'\n\nexport type UseDebounceFnReturn = {\n /**\n * Debounce a function execution.\n *\n * @param fn - The function to debounce.\n * @param delay - Override the default delay in milliseconds (optional).\n */\n debounce: (fn: () => any, delay?: number) => void\n /**\n * Cancel the debounce.\n */\n cancel: () => void\n /**\n * Whether a debounced call is pending.\n */\n isPending: boolean\n}\n\nexport function useDebounceFn(defaultDelay: number): UseDebounceFnReturn {\n const timeoutRef = React.useRef<NodeJS.Timeout | number>(0)\n\n // use async transitions in React 19\n const [isPending, setIsPending] = React.useState(false)\n\n const cancel = React.useCallback(() => {\n setIsPending(false)\n clearTimeout(timeoutRef.current)\n }, [])\n\n const debounce = React.useCallback(\n (fn: () => any, delay: number = defaultDelay) => {\n cancel()\n if (!delay) {\n fn()\n return\n }\n setIsPending(true)\n timeoutRef.current = setTimeout(() => {\n setIsPending(false)\n fn()\n }, delay)\n },\n [cancel, defaultDelay],\n )\n\n // clear the debounce on unmount\n React.useEffect(() => cancel, [cancel])\n\n return { debounce, cancel, isPending }\n}\n"]}
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1hook/use-debounce-fn",
3
- "version": "0.0.4-beta-0",
3
+ "version": "0.0.5",
4
4
  "files": [
5
5
  "dist",
6
6
  "README.md"
@@ -13,14 +13,6 @@
13
13
  "default": "./dist/index.js"
14
14
  }
15
15
  },
16
- "scripts": {
17
- "build": "NODE_ENV=production tsup",
18
- "dev": "concurrently \"tsup --watch\" \"vitest\"",
19
- "test": "vitest run && tsc --noEmit",
20
- "lint": "eslint . && tsc --noEmit",
21
- "lint:eslint": "eslint .",
22
- "lint:typescript": "tsc --noEmit"
23
- },
24
16
  "peerDependencies": {
25
17
  "@types/react": ">=18.0.0 || >=19.0.0",
26
18
  "@types/react-dom": ">=18.0.0 || >=19.0.0",
@@ -30,7 +22,7 @@
30
22
  "tag": "beta",
31
23
  "repository": {
32
24
  "type": "git",
33
- "url": "https://github.com/L-Blondy/one-hook"
25
+ "url": "git+https://github.com/L-Blondy/one-hook"
34
26
  },
35
27
  "homepage": "https://github.com/L-Blondy/one-hook",
36
28
  "bugs": {
@@ -43,5 +35,13 @@
43
35
  "@types/react-dom": {
44
36
  "optional": true
45
37
  }
38
+ },
39
+ "scripts": {
40
+ "build": "NODE_ENV=production tsup",
41
+ "dev": "concurrently \"tsup --watch\" \"vitest\"",
42
+ "test": "vitest run && tsc --noEmit",
43
+ "lint": "eslint . && tsc --noEmit",
44
+ "lint:eslint": "eslint .",
45
+ "lint:typescript": "tsc --noEmit"
46
46
  }
47
47
  }