@bcrumbs.net/bc-ui 0.0.4 → 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/index.esm.js +4 -2
- package/package.json +1 -1
package/index.esm.js
CHANGED
|
@@ -16805,6 +16805,7 @@ function useDebounce(callback, delay) {
|
|
|
16805
16805
|
const [debouncedValue, setDebouncedValue] = useState(undefined);
|
|
16806
16806
|
const callbackRef = useRef(callback);
|
|
16807
16807
|
const timeoutRef = useRef(null);
|
|
16808
|
+
const lastCalledValueRef = useRef(undefined);
|
|
16808
16809
|
// Update the callback ref when callback changes
|
|
16809
16810
|
useEffect(() => {
|
|
16810
16811
|
callbackRef.current = callback;
|
|
@@ -16814,10 +16815,11 @@ function useDebounce(callback, delay) {
|
|
|
16814
16815
|
if (timeoutRef.current) {
|
|
16815
16816
|
clearTimeout(timeoutRef.current);
|
|
16816
16817
|
}
|
|
16817
|
-
// Only set a new timeout if we have a value to debounce
|
|
16818
|
-
if (debouncedValue !== undefined) {
|
|
16818
|
+
// Only set a new timeout if we have a value to debounce and it's different from the last called value
|
|
16819
|
+
if (debouncedValue !== undefined && debouncedValue !== lastCalledValueRef.current) {
|
|
16819
16820
|
timeoutRef.current = setTimeout(() => {
|
|
16820
16821
|
callbackRef.current(debouncedValue);
|
|
16822
|
+
lastCalledValueRef.current = debouncedValue;
|
|
16821
16823
|
}, delay);
|
|
16822
16824
|
}
|
|
16823
16825
|
// Cleanup function
|