@usefy/use-debounce 0.0.2

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,69 @@
1
+ /**
2
+ * Options for useDebounce hook
3
+ */
4
+ interface UseDebounceOptions {
5
+ /**
6
+ * Maximum time the debounced value can be delayed
7
+ * @default undefined (no maximum)
8
+ */
9
+ maxWait?: number;
10
+ /**
11
+ * Whether to update the debounced value on the leading edge
12
+ * @default false
13
+ */
14
+ leading?: boolean;
15
+ /**
16
+ * Whether to update the debounced value on the trailing edge
17
+ * @default true
18
+ */
19
+ trailing?: boolean;
20
+ }
21
+ /**
22
+ * Debounces a value by delaying updates until after a specified delay period has elapsed
23
+ * since the last time the value changed.
24
+ *
25
+ * @template T - The type of the value to debounce
26
+ * @param value - The value to debounce
27
+ * @param delay - The delay in milliseconds (default: 500ms)
28
+ * @param options - Additional options for controlling debounce behavior
29
+ * @returns The debounced value
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * function SearchInput() {
34
+ * const [searchTerm, setSearchTerm] = useState('');
35
+ * const debouncedSearchTerm = useDebounce(searchTerm, 500);
36
+ *
37
+ * useEffect(() => {
38
+ * if (debouncedSearchTerm) {
39
+ * // API call with debounced value
40
+ * searchAPI(debouncedSearchTerm);
41
+ * }
42
+ * }, [debouncedSearchTerm]);
43
+ *
44
+ * return (
45
+ * <input
46
+ * type="text"
47
+ * value={searchTerm}
48
+ * onChange={(e) => setSearchTerm(e.target.value)}
49
+ * placeholder="Search..."
50
+ * />
51
+ * );
52
+ * }
53
+ * ```
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * // With leading edge update
58
+ * const debouncedValue = useDebounce(value, 300, { leading: true });
59
+ * ```
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * // With maximum wait time
64
+ * const debouncedValue = useDebounce(value, 500, { maxWait: 2000 });
65
+ * ```
66
+ */
67
+ declare function useDebounce<T>(value: T, delay?: number, options?: UseDebounceOptions): T;
68
+
69
+ export { type UseDebounceOptions, useDebounce };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Options for useDebounce hook
3
+ */
4
+ interface UseDebounceOptions {
5
+ /**
6
+ * Maximum time the debounced value can be delayed
7
+ * @default undefined (no maximum)
8
+ */
9
+ maxWait?: number;
10
+ /**
11
+ * Whether to update the debounced value on the leading edge
12
+ * @default false
13
+ */
14
+ leading?: boolean;
15
+ /**
16
+ * Whether to update the debounced value on the trailing edge
17
+ * @default true
18
+ */
19
+ trailing?: boolean;
20
+ }
21
+ /**
22
+ * Debounces a value by delaying updates until after a specified delay period has elapsed
23
+ * since the last time the value changed.
24
+ *
25
+ * @template T - The type of the value to debounce
26
+ * @param value - The value to debounce
27
+ * @param delay - The delay in milliseconds (default: 500ms)
28
+ * @param options - Additional options for controlling debounce behavior
29
+ * @returns The debounced value
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * function SearchInput() {
34
+ * const [searchTerm, setSearchTerm] = useState('');
35
+ * const debouncedSearchTerm = useDebounce(searchTerm, 500);
36
+ *
37
+ * useEffect(() => {
38
+ * if (debouncedSearchTerm) {
39
+ * // API call with debounced value
40
+ * searchAPI(debouncedSearchTerm);
41
+ * }
42
+ * }, [debouncedSearchTerm]);
43
+ *
44
+ * return (
45
+ * <input
46
+ * type="text"
47
+ * value={searchTerm}
48
+ * onChange={(e) => setSearchTerm(e.target.value)}
49
+ * placeholder="Search..."
50
+ * />
51
+ * );
52
+ * }
53
+ * ```
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * // With leading edge update
58
+ * const debouncedValue = useDebounce(value, 300, { leading: true });
59
+ * ```
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * // With maximum wait time
64
+ * const debouncedValue = useDebounce(value, 500, { maxWait: 2000 });
65
+ * ```
66
+ */
67
+ declare function useDebounce<T>(value: T, delay?: number, options?: UseDebounceOptions): T;
68
+
69
+ export { type UseDebounceOptions, useDebounce };
package/dist/index.js ADDED
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useDebounce: () => useDebounce
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/useDebounce.ts
28
+ var import_react = require("react");
29
+ function useDebounce(value, delay = 500, options = {}) {
30
+ const wait = delay || 0;
31
+ const leading = options.leading ?? false;
32
+ const trailing = options.trailing !== void 0 ? options.trailing : true;
33
+ const maxing = "maxWait" in options;
34
+ const maxWait = maxing ? Math.max(options.maxWait || 0, wait) : void 0;
35
+ const [debouncedValue, setDebouncedValue] = (0, import_react.useState)(value);
36
+ const timerIdRef = (0, import_react.useRef)(
37
+ void 0
38
+ );
39
+ const lastCallTimeRef = (0, import_react.useRef)(void 0);
40
+ const lastInvokeTimeRef = (0, import_react.useRef)(0);
41
+ const lastValueRef = (0, import_react.useRef)(value);
42
+ const prevValueRef = (0, import_react.useRef)(value);
43
+ const waitRef = (0, import_react.useRef)(wait);
44
+ const leadingRef = (0, import_react.useRef)(leading);
45
+ const trailingRef = (0, import_react.useRef)(trailing);
46
+ const maxingRef = (0, import_react.useRef)(maxing);
47
+ const maxWaitRef = (0, import_react.useRef)(maxWait);
48
+ waitRef.current = wait;
49
+ leadingRef.current = leading;
50
+ trailingRef.current = trailing;
51
+ maxingRef.current = maxing;
52
+ maxWaitRef.current = maxWait;
53
+ const now = () => Date.now();
54
+ const shouldInvokeRef = (0, import_react.useRef)(() => false);
55
+ const invokeRef = (0, import_react.useRef)(() => {
56
+ });
57
+ const remainingWaitRef = (0, import_react.useRef)(() => 0);
58
+ const timerExpiredRef = (0, import_react.useRef)(() => {
59
+ });
60
+ const trailingEdgeRef = (0, import_react.useRef)(() => {
61
+ });
62
+ const leadingEdgeRef = (0, import_react.useRef)(() => {
63
+ });
64
+ shouldInvokeRef.current = (time) => {
65
+ const lastCallTime = lastCallTimeRef.current;
66
+ if (lastCallTime === void 0) {
67
+ return true;
68
+ }
69
+ const timeSinceLastCall = time - lastCallTime;
70
+ const timeSinceLastInvoke = time - lastInvokeTimeRef.current;
71
+ return timeSinceLastCall >= waitRef.current || timeSinceLastCall < 0 || // System time went backwards
72
+ maxingRef.current && timeSinceLastInvoke >= maxWaitRef.current;
73
+ };
74
+ invokeRef.current = (time) => {
75
+ setDebouncedValue(lastValueRef.current);
76
+ lastInvokeTimeRef.current = time;
77
+ };
78
+ remainingWaitRef.current = (time) => {
79
+ const lastCallTime = lastCallTimeRef.current;
80
+ if (lastCallTime === void 0) {
81
+ return waitRef.current;
82
+ }
83
+ const timeSinceLastCall = time - lastCallTime;
84
+ const timeSinceLastInvoke = time - lastInvokeTimeRef.current;
85
+ const timeWaiting = waitRef.current - timeSinceLastCall;
86
+ return maxingRef.current ? Math.min(
87
+ timeWaiting,
88
+ maxWaitRef.current - timeSinceLastInvoke
89
+ ) : timeWaiting;
90
+ };
91
+ trailingEdgeRef.current = (time) => {
92
+ timerIdRef.current = void 0;
93
+ if (trailingRef.current && lastCallTimeRef.current !== void 0) {
94
+ invokeRef.current(time);
95
+ }
96
+ };
97
+ timerExpiredRef.current = () => {
98
+ const time = now();
99
+ if (shouldInvokeRef.current(time)) {
100
+ trailingEdgeRef.current(time);
101
+ } else {
102
+ timerIdRef.current = setTimeout(
103
+ () => timerExpiredRef.current(),
104
+ remainingWaitRef.current(time)
105
+ );
106
+ }
107
+ };
108
+ leadingEdgeRef.current = (time) => {
109
+ lastInvokeTimeRef.current = time;
110
+ timerIdRef.current = setTimeout(
111
+ () => timerExpiredRef.current(),
112
+ waitRef.current
113
+ );
114
+ if (leadingRef.current) {
115
+ invokeRef.current(time);
116
+ }
117
+ };
118
+ (0, import_react.useEffect)(() => {
119
+ return () => {
120
+ if (timerIdRef.current !== void 0) {
121
+ clearTimeout(timerIdRef.current);
122
+ }
123
+ };
124
+ }, []);
125
+ (0, import_react.useEffect)(() => {
126
+ if (Object.is(prevValueRef.current, value)) {
127
+ return;
128
+ }
129
+ prevValueRef.current = value;
130
+ const time = now();
131
+ const isInvoking = shouldInvokeRef.current(time);
132
+ lastValueRef.current = value;
133
+ lastCallTimeRef.current = time;
134
+ if (isInvoking) {
135
+ if (timerIdRef.current === void 0) {
136
+ leadingEdgeRef.current(time);
137
+ } else if (maxingRef.current) {
138
+ clearTimeout(timerIdRef.current);
139
+ timerIdRef.current = setTimeout(
140
+ () => timerExpiredRef.current(),
141
+ waitRef.current
142
+ );
143
+ invokeRef.current(time);
144
+ }
145
+ } else {
146
+ if (timerIdRef.current === void 0) {
147
+ timerIdRef.current = setTimeout(
148
+ () => timerExpiredRef.current(),
149
+ waitRef.current
150
+ );
151
+ }
152
+ }
153
+ }, [value]);
154
+ return debouncedValue;
155
+ }
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ useDebounce
159
+ });
160
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/useDebounce.ts"],"sourcesContent":["export { useDebounce, type UseDebounceOptions } from \"./useDebounce\";\r\n","import { useEffect, useRef, useState } from \"react\";\r\n\r\n/**\r\n * Options for useDebounce hook\r\n */\r\nexport interface UseDebounceOptions {\r\n /**\r\n * Maximum time the debounced value can be delayed\r\n * @default undefined (no maximum)\r\n */\r\n maxWait?: number;\r\n /**\r\n * Whether to update the debounced value on the leading edge\r\n * @default false\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the debounced value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Debounces a value by delaying updates until after a specified delay period has elapsed\r\n * since the last time the value changed.\r\n *\r\n * @template T - The type of the value to debounce\r\n * @param value - The value to debounce\r\n * @param delay - The delay in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling debounce behavior\r\n * @returns The debounced value\r\n *\r\n * @example\r\n * ```tsx\r\n * function SearchInput() {\r\n * const [searchTerm, setSearchTerm] = useState('');\r\n * const debouncedSearchTerm = useDebounce(searchTerm, 500);\r\n *\r\n * useEffect(() => {\r\n * if (debouncedSearchTerm) {\r\n * // API call with debounced value\r\n * searchAPI(debouncedSearchTerm);\r\n * }\r\n * }, [debouncedSearchTerm]);\r\n *\r\n * return (\r\n * <input\r\n * type=\"text\"\r\n * value={searchTerm}\r\n * onChange={(e) => setSearchTerm(e.target.value)}\r\n * placeholder=\"Search...\"\r\n * />\r\n * );\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge update\r\n * const debouncedValue = useDebounce(value, 300, { leading: true });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With maximum wait time\r\n * const debouncedValue = useDebounce(value, 500, { maxWait: 2000 });\r\n * ```\r\n */\r\nexport function useDebounce<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseDebounceOptions = {}\r\n): T {\r\n // Parse options\r\n const wait = delay || 0;\r\n const leading = options.leading ?? false;\r\n const trailing = options.trailing !== undefined ? options.trailing : true;\r\n const maxing = \"maxWait\" in options;\r\n const maxWait = maxing ? Math.max(options.maxWait || 0, wait) : undefined;\r\n\r\n const [debouncedValue, setDebouncedValue] = useState<T>(value);\r\n const timerIdRef = useRef<ReturnType<typeof setTimeout> | undefined>(\r\n undefined\r\n );\r\n const lastCallTimeRef = useRef<number | undefined>(undefined);\r\n const lastInvokeTimeRef = useRef<number>(0);\r\n const lastValueRef = useRef<T>(value);\r\n const prevValueRef = useRef<T>(value); // Track previous value to detect actual changes\r\n\r\n // Store options in refs to access latest values in timer callbacks\r\n const waitRef = useRef(wait);\r\n const leadingRef = useRef(leading);\r\n const trailingRef = useRef(trailing);\r\n const maxingRef = useRef(maxing);\r\n const maxWaitRef = useRef(maxWait);\r\n\r\n // Update refs when options change\r\n waitRef.current = wait;\r\n leadingRef.current = leading;\r\n trailingRef.current = trailing;\r\n maxingRef.current = maxing;\r\n maxWaitRef.current = maxWait;\r\n\r\n // Helper function to get current time\r\n const now = () => Date.now();\r\n\r\n // Define helper functions using refs for latest values\r\n const shouldInvokeRef = useRef<(time: number) => boolean>(() => false);\r\n const invokeRef = useRef<(time: number) => void>(() => {});\r\n const remainingWaitRef = useRef<(time: number) => number>(() => 0);\r\n const timerExpiredRef = useRef<() => void>(() => {});\r\n const trailingEdgeRef = useRef<(time: number) => void>(() => {});\r\n const leadingEdgeRef = useRef<(time: number) => void>(() => {});\r\n\r\n // Helper function: shouldInvoke\r\n shouldInvokeRef.current = (time: number): boolean => {\r\n const lastCallTime = lastCallTimeRef.current;\r\n if (lastCallTime === undefined) {\r\n return true; // First call\r\n }\r\n\r\n const timeSinceLastCall = time - lastCallTime;\r\n const timeSinceLastInvoke = time - lastInvokeTimeRef.current;\r\n\r\n return (\r\n timeSinceLastCall >= waitRef.current ||\r\n timeSinceLastCall < 0 || // System time went backwards\r\n (maxingRef.current &&\r\n timeSinceLastInvoke >= (maxWaitRef.current as number))\r\n );\r\n };\r\n\r\n // Helper function: invokeFunc\r\n invokeRef.current = (time: number): void => {\r\n setDebouncedValue(lastValueRef.current);\r\n lastInvokeTimeRef.current = time;\r\n };\r\n\r\n // Helper function: remainingWait\r\n remainingWaitRef.current = (time: number): number => {\r\n const lastCallTime = lastCallTimeRef.current;\r\n if (lastCallTime === undefined) {\r\n return waitRef.current;\r\n }\r\n\r\n const timeSinceLastCall = time - lastCallTime;\r\n const timeSinceLastInvoke = time - lastInvokeTimeRef.current;\r\n const timeWaiting = waitRef.current - timeSinceLastCall;\r\n\r\n return maxingRef.current\r\n ? Math.min(\r\n timeWaiting,\r\n (maxWaitRef.current as number) - timeSinceLastInvoke\r\n )\r\n : timeWaiting;\r\n };\r\n\r\n // Helper function: trailingEdge\r\n trailingEdgeRef.current = (time: number): void => {\r\n timerIdRef.current = undefined;\r\n\r\n // Only invoke if we have `lastValueRef.current` which means `value` has been\r\n // debounced at least once.\r\n if (trailingRef.current && lastCallTimeRef.current !== undefined) {\r\n invokeRef.current(time);\r\n }\r\n };\r\n\r\n // Helper function: timerExpired\r\n timerExpiredRef.current = (): void => {\r\n const time = now();\r\n if (shouldInvokeRef.current(time)) {\r\n trailingEdgeRef.current(time);\r\n } else {\r\n // Restart the timer.\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n remainingWaitRef.current(time)\r\n );\r\n }\r\n };\r\n\r\n // Helper function: leadingEdge\r\n leadingEdgeRef.current = (time: number): void => {\r\n // Reset any `maxWait` timer.\r\n lastInvokeTimeRef.current = time;\r\n // Start the timer for the trailing edge.\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n // Invoke the leading edge.\r\n if (leadingRef.current) {\r\n invokeRef.current(time);\r\n }\r\n };\r\n\r\n // Cleanup on unmount only\r\n useEffect(() => {\r\n return () => {\r\n if (timerIdRef.current !== undefined) {\r\n clearTimeout(timerIdRef.current);\r\n }\r\n };\r\n }, []);\r\n\r\n // Main debounce effect - runs when value changes\r\n useEffect(() => {\r\n // Skip if value hasn't actually changed (prevents initial render from consuming leading edge)\r\n if (Object.is(prevValueRef.current, value)) {\r\n return;\r\n }\r\n prevValueRef.current = value;\r\n\r\n const time = now();\r\n const isInvoking = shouldInvokeRef.current(time);\r\n\r\n // Update lastValueRef with current value\r\n lastValueRef.current = value;\r\n lastCallTimeRef.current = time;\r\n\r\n if (isInvoking) {\r\n if (timerIdRef.current === undefined) {\r\n leadingEdgeRef.current(time);\r\n } else if (maxingRef.current) {\r\n // Handle invocations in a tight loop.\r\n clearTimeout(timerIdRef.current);\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n invokeRef.current(time);\r\n }\r\n } else {\r\n if (timerIdRef.current === undefined) {\r\n // Start timer with wait\r\n // remainingWait is only used inside timerExpired for restarting\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n }\r\n }\r\n // No cleanup here - timer should persist across value changes\r\n // This is the key difference from the previous implementation\r\n }, [value]);\r\n\r\n return debouncedValue;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4C;AAqErC,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AAEH,QAAM,OAAO,SAAS;AACtB,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,WAAW,QAAQ,aAAa,SAAY,QAAQ,WAAW;AACrE,QAAM,SAAS,aAAa;AAC5B,QAAM,UAAU,SAAS,KAAK,IAAI,QAAQ,WAAW,GAAG,IAAI,IAAI;AAEhE,QAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAAY,KAAK;AAC7D,QAAM,iBAAa;AAAA,IACjB;AAAA,EACF;AACA,QAAM,sBAAkB,qBAA2B,MAAS;AAC5D,QAAM,wBAAoB,qBAAe,CAAC;AAC1C,QAAM,mBAAe,qBAAU,KAAK;AACpC,QAAM,mBAAe,qBAAU,KAAK;AAGpC,QAAM,cAAU,qBAAO,IAAI;AAC3B,QAAM,iBAAa,qBAAO,OAAO;AACjC,QAAM,kBAAc,qBAAO,QAAQ;AACnC,QAAM,gBAAY,qBAAO,MAAM;AAC/B,QAAM,iBAAa,qBAAO,OAAO;AAGjC,UAAQ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GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,133 @@
1
+ // src/useDebounce.ts
2
+ import { useEffect, useRef, useState } from "react";
3
+ function useDebounce(value, delay = 500, options = {}) {
4
+ const wait = delay || 0;
5
+ const leading = options.leading ?? false;
6
+ const trailing = options.trailing !== void 0 ? options.trailing : true;
7
+ const maxing = "maxWait" in options;
8
+ const maxWait = maxing ? Math.max(options.maxWait || 0, wait) : void 0;
9
+ const [debouncedValue, setDebouncedValue] = useState(value);
10
+ const timerIdRef = useRef(
11
+ void 0
12
+ );
13
+ const lastCallTimeRef = useRef(void 0);
14
+ const lastInvokeTimeRef = useRef(0);
15
+ const lastValueRef = useRef(value);
16
+ const prevValueRef = useRef(value);
17
+ const waitRef = useRef(wait);
18
+ const leadingRef = useRef(leading);
19
+ const trailingRef = useRef(trailing);
20
+ const maxingRef = useRef(maxing);
21
+ const maxWaitRef = useRef(maxWait);
22
+ waitRef.current = wait;
23
+ leadingRef.current = leading;
24
+ trailingRef.current = trailing;
25
+ maxingRef.current = maxing;
26
+ maxWaitRef.current = maxWait;
27
+ const now = () => Date.now();
28
+ const shouldInvokeRef = useRef(() => false);
29
+ const invokeRef = useRef(() => {
30
+ });
31
+ const remainingWaitRef = useRef(() => 0);
32
+ const timerExpiredRef = useRef(() => {
33
+ });
34
+ const trailingEdgeRef = useRef(() => {
35
+ });
36
+ const leadingEdgeRef = useRef(() => {
37
+ });
38
+ shouldInvokeRef.current = (time) => {
39
+ const lastCallTime = lastCallTimeRef.current;
40
+ if (lastCallTime === void 0) {
41
+ return true;
42
+ }
43
+ const timeSinceLastCall = time - lastCallTime;
44
+ const timeSinceLastInvoke = time - lastInvokeTimeRef.current;
45
+ return timeSinceLastCall >= waitRef.current || timeSinceLastCall < 0 || // System time went backwards
46
+ maxingRef.current && timeSinceLastInvoke >= maxWaitRef.current;
47
+ };
48
+ invokeRef.current = (time) => {
49
+ setDebouncedValue(lastValueRef.current);
50
+ lastInvokeTimeRef.current = time;
51
+ };
52
+ remainingWaitRef.current = (time) => {
53
+ const lastCallTime = lastCallTimeRef.current;
54
+ if (lastCallTime === void 0) {
55
+ return waitRef.current;
56
+ }
57
+ const timeSinceLastCall = time - lastCallTime;
58
+ const timeSinceLastInvoke = time - lastInvokeTimeRef.current;
59
+ const timeWaiting = waitRef.current - timeSinceLastCall;
60
+ return maxingRef.current ? Math.min(
61
+ timeWaiting,
62
+ maxWaitRef.current - timeSinceLastInvoke
63
+ ) : timeWaiting;
64
+ };
65
+ trailingEdgeRef.current = (time) => {
66
+ timerIdRef.current = void 0;
67
+ if (trailingRef.current && lastCallTimeRef.current !== void 0) {
68
+ invokeRef.current(time);
69
+ }
70
+ };
71
+ timerExpiredRef.current = () => {
72
+ const time = now();
73
+ if (shouldInvokeRef.current(time)) {
74
+ trailingEdgeRef.current(time);
75
+ } else {
76
+ timerIdRef.current = setTimeout(
77
+ () => timerExpiredRef.current(),
78
+ remainingWaitRef.current(time)
79
+ );
80
+ }
81
+ };
82
+ leadingEdgeRef.current = (time) => {
83
+ lastInvokeTimeRef.current = time;
84
+ timerIdRef.current = setTimeout(
85
+ () => timerExpiredRef.current(),
86
+ waitRef.current
87
+ );
88
+ if (leadingRef.current) {
89
+ invokeRef.current(time);
90
+ }
91
+ };
92
+ useEffect(() => {
93
+ return () => {
94
+ if (timerIdRef.current !== void 0) {
95
+ clearTimeout(timerIdRef.current);
96
+ }
97
+ };
98
+ }, []);
99
+ useEffect(() => {
100
+ if (Object.is(prevValueRef.current, value)) {
101
+ return;
102
+ }
103
+ prevValueRef.current = value;
104
+ const time = now();
105
+ const isInvoking = shouldInvokeRef.current(time);
106
+ lastValueRef.current = value;
107
+ lastCallTimeRef.current = time;
108
+ if (isInvoking) {
109
+ if (timerIdRef.current === void 0) {
110
+ leadingEdgeRef.current(time);
111
+ } else if (maxingRef.current) {
112
+ clearTimeout(timerIdRef.current);
113
+ timerIdRef.current = setTimeout(
114
+ () => timerExpiredRef.current(),
115
+ waitRef.current
116
+ );
117
+ invokeRef.current(time);
118
+ }
119
+ } else {
120
+ if (timerIdRef.current === void 0) {
121
+ timerIdRef.current = setTimeout(
122
+ () => timerExpiredRef.current(),
123
+ waitRef.current
124
+ );
125
+ }
126
+ }
127
+ }, [value]);
128
+ return debouncedValue;
129
+ }
130
+ export {
131
+ useDebounce
132
+ };
133
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useDebounce.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\r\n\r\n/**\r\n * Options for useDebounce hook\r\n */\r\nexport interface UseDebounceOptions {\r\n /**\r\n * Maximum time the debounced value can be delayed\r\n * @default undefined (no maximum)\r\n */\r\n maxWait?: number;\r\n /**\r\n * Whether to update the debounced value on the leading edge\r\n * @default false\r\n */\r\n leading?: boolean;\r\n /**\r\n * Whether to update the debounced value on the trailing edge\r\n * @default true\r\n */\r\n trailing?: boolean;\r\n}\r\n\r\n/**\r\n * Debounces a value by delaying updates until after a specified delay period has elapsed\r\n * since the last time the value changed.\r\n *\r\n * @template T - The type of the value to debounce\r\n * @param value - The value to debounce\r\n * @param delay - The delay in milliseconds (default: 500ms)\r\n * @param options - Additional options for controlling debounce behavior\r\n * @returns The debounced value\r\n *\r\n * @example\r\n * ```tsx\r\n * function SearchInput() {\r\n * const [searchTerm, setSearchTerm] = useState('');\r\n * const debouncedSearchTerm = useDebounce(searchTerm, 500);\r\n *\r\n * useEffect(() => {\r\n * if (debouncedSearchTerm) {\r\n * // API call with debounced value\r\n * searchAPI(debouncedSearchTerm);\r\n * }\r\n * }, [debouncedSearchTerm]);\r\n *\r\n * return (\r\n * <input\r\n * type=\"text\"\r\n * value={searchTerm}\r\n * onChange={(e) => setSearchTerm(e.target.value)}\r\n * placeholder=\"Search...\"\r\n * />\r\n * );\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With leading edge update\r\n * const debouncedValue = useDebounce(value, 300, { leading: true });\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * // With maximum wait time\r\n * const debouncedValue = useDebounce(value, 500, { maxWait: 2000 });\r\n * ```\r\n */\r\nexport function useDebounce<T>(\r\n value: T,\r\n delay: number = 500,\r\n options: UseDebounceOptions = {}\r\n): T {\r\n // Parse options\r\n const wait = delay || 0;\r\n const leading = options.leading ?? false;\r\n const trailing = options.trailing !== undefined ? options.trailing : true;\r\n const maxing = \"maxWait\" in options;\r\n const maxWait = maxing ? Math.max(options.maxWait || 0, wait) : undefined;\r\n\r\n const [debouncedValue, setDebouncedValue] = useState<T>(value);\r\n const timerIdRef = useRef<ReturnType<typeof setTimeout> | undefined>(\r\n undefined\r\n );\r\n const lastCallTimeRef = useRef<number | undefined>(undefined);\r\n const lastInvokeTimeRef = useRef<number>(0);\r\n const lastValueRef = useRef<T>(value);\r\n const prevValueRef = useRef<T>(value); // Track previous value to detect actual changes\r\n\r\n // Store options in refs to access latest values in timer callbacks\r\n const waitRef = useRef(wait);\r\n const leadingRef = useRef(leading);\r\n const trailingRef = useRef(trailing);\r\n const maxingRef = useRef(maxing);\r\n const maxWaitRef = useRef(maxWait);\r\n\r\n // Update refs when options change\r\n waitRef.current = wait;\r\n leadingRef.current = leading;\r\n trailingRef.current = trailing;\r\n maxingRef.current = maxing;\r\n maxWaitRef.current = maxWait;\r\n\r\n // Helper function to get current time\r\n const now = () => Date.now();\r\n\r\n // Define helper functions using refs for latest values\r\n const shouldInvokeRef = useRef<(time: number) => boolean>(() => false);\r\n const invokeRef = useRef<(time: number) => void>(() => {});\r\n const remainingWaitRef = useRef<(time: number) => number>(() => 0);\r\n const timerExpiredRef = useRef<() => void>(() => {});\r\n const trailingEdgeRef = useRef<(time: number) => void>(() => {});\r\n const leadingEdgeRef = useRef<(time: number) => void>(() => {});\r\n\r\n // Helper function: shouldInvoke\r\n shouldInvokeRef.current = (time: number): boolean => {\r\n const lastCallTime = lastCallTimeRef.current;\r\n if (lastCallTime === undefined) {\r\n return true; // First call\r\n }\r\n\r\n const timeSinceLastCall = time - lastCallTime;\r\n const timeSinceLastInvoke = time - lastInvokeTimeRef.current;\r\n\r\n return (\r\n timeSinceLastCall >= waitRef.current ||\r\n timeSinceLastCall < 0 || // System time went backwards\r\n (maxingRef.current &&\r\n timeSinceLastInvoke >= (maxWaitRef.current as number))\r\n );\r\n };\r\n\r\n // Helper function: invokeFunc\r\n invokeRef.current = (time: number): void => {\r\n setDebouncedValue(lastValueRef.current);\r\n lastInvokeTimeRef.current = time;\r\n };\r\n\r\n // Helper function: remainingWait\r\n remainingWaitRef.current = (time: number): number => {\r\n const lastCallTime = lastCallTimeRef.current;\r\n if (lastCallTime === undefined) {\r\n return waitRef.current;\r\n }\r\n\r\n const timeSinceLastCall = time - lastCallTime;\r\n const timeSinceLastInvoke = time - lastInvokeTimeRef.current;\r\n const timeWaiting = waitRef.current - timeSinceLastCall;\r\n\r\n return maxingRef.current\r\n ? Math.min(\r\n timeWaiting,\r\n (maxWaitRef.current as number) - timeSinceLastInvoke\r\n )\r\n : timeWaiting;\r\n };\r\n\r\n // Helper function: trailingEdge\r\n trailingEdgeRef.current = (time: number): void => {\r\n timerIdRef.current = undefined;\r\n\r\n // Only invoke if we have `lastValueRef.current` which means `value` has been\r\n // debounced at least once.\r\n if (trailingRef.current && lastCallTimeRef.current !== undefined) {\r\n invokeRef.current(time);\r\n }\r\n };\r\n\r\n // Helper function: timerExpired\r\n timerExpiredRef.current = (): void => {\r\n const time = now();\r\n if (shouldInvokeRef.current(time)) {\r\n trailingEdgeRef.current(time);\r\n } else {\r\n // Restart the timer.\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n remainingWaitRef.current(time)\r\n );\r\n }\r\n };\r\n\r\n // Helper function: leadingEdge\r\n leadingEdgeRef.current = (time: number): void => {\r\n // Reset any `maxWait` timer.\r\n lastInvokeTimeRef.current = time;\r\n // Start the timer for the trailing edge.\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n // Invoke the leading edge.\r\n if (leadingRef.current) {\r\n invokeRef.current(time);\r\n }\r\n };\r\n\r\n // Cleanup on unmount only\r\n useEffect(() => {\r\n return () => {\r\n if (timerIdRef.current !== undefined) {\r\n clearTimeout(timerIdRef.current);\r\n }\r\n };\r\n }, []);\r\n\r\n // Main debounce effect - runs when value changes\r\n useEffect(() => {\r\n // Skip if value hasn't actually changed (prevents initial render from consuming leading edge)\r\n if (Object.is(prevValueRef.current, value)) {\r\n return;\r\n }\r\n prevValueRef.current = value;\r\n\r\n const time = now();\r\n const isInvoking = shouldInvokeRef.current(time);\r\n\r\n // Update lastValueRef with current value\r\n lastValueRef.current = value;\r\n lastCallTimeRef.current = time;\r\n\r\n if (isInvoking) {\r\n if (timerIdRef.current === undefined) {\r\n leadingEdgeRef.current(time);\r\n } else if (maxingRef.current) {\r\n // Handle invocations in a tight loop.\r\n clearTimeout(timerIdRef.current);\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n invokeRef.current(time);\r\n }\r\n } else {\r\n if (timerIdRef.current === undefined) {\r\n // Start timer with wait\r\n // remainingWait is only used inside timerExpired for restarting\r\n timerIdRef.current = setTimeout(\r\n () => timerExpiredRef.current(),\r\n waitRef.current\r\n );\r\n }\r\n }\r\n // No cleanup here - timer should persist across value changes\r\n // This is the key difference from the previous implementation\r\n }, [value]);\r\n\r\n return debouncedValue;\r\n}\r\n"],"mappings":";AAAA,SAAS,WAAW,QAAQ,gBAAgB;AAqErC,SAAS,YACd,OACA,QAAgB,KAChB,UAA8B,CAAC,GAC5B;AAEH,QAAM,OAAO,SAAS;AACtB,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,WAAW,QAAQ,aAAa,SAAY,QAAQ,WAAW;AACrE,QAAM,SAAS,aAAa;AAC5B,QAAM,UAAU,SAAS,KAAK,IAAI,QAAQ,WAAW,GAAG,IAAI,IAAI;AAEhE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AW;AACpC,uBAAe,QAAQ,IAAI;AAAA,MAC7B,WAAW,UAAU,SAAS;AAE5B,qBAAa,WAAW,OAAO;AAC/B,mBAAW,UAAU;AAAA,UACnB,MAAM,gBAAgB,QAAQ;AAAA,UAC9B,QAAQ;AAAA,QACV;AACA,kBAAU,QAAQ,IAAI;AAAA,MACxB;AAAA,IACF,OAAO;AACL,UAAI,WAAW,YAAY,QAAW;AAGpC,mBAAW,UAAU;AAAA,UACnB,MAAM,gBAAgB,QAAQ;AAAA,UAC9B,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EAGF,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@usefy/use-debounce",
3
+ "version": "0.0.2",
4
+ "description": "A React hook for value debouncing with leading/trailing edge and maxWait options",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "peerDependencies": {
20
+ "react": "^18.0.0 || ^19.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@testing-library/jest-dom": "^6.9.1",
24
+ "@testing-library/react": "^16.3.1",
25
+ "@testing-library/user-event": "^14.6.1",
26
+ "@types/react": "^19.0.0",
27
+ "jsdom": "^27.3.0",
28
+ "react": "^19.0.0",
29
+ "rimraf": "^6.0.1",
30
+ "tsup": "^8.0.0",
31
+ "typescript": "^5.0.0",
32
+ "vitest": "^4.0.16"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/geon0529/usefy.git",
40
+ "directory": "packages/use-debounce"
41
+ },
42
+ "license": "MIT",
43
+ "keywords": [
44
+ "react",
45
+ "hooks",
46
+ "debounce",
47
+ "delay",
48
+ "throttle"
49
+ ],
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "typecheck": "tsc --noEmit",
56
+ "clean": "rimraf dist"
57
+ }
58
+ }