Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
'use client';
import { useState, useRef, useCallback, useEffect } from 'react';
function useDebouncedValue(value, wait, options = { leading: false }) {
const [_value, setValue] = useState(value);
const mountedRef = useRef(false);
const timeoutRef = useRef(null);
const cooldownRef = useRef(false);
const cancel = useCallback(() => window.clearTimeout(timeoutRef.current), []);
useEffect(() => {
if (mountedRef.current) {
if (!cooldownRef.current && options.leading) {
cooldownRef.current = true;
setValue(value);
} else {
cancel();
timeoutRef.current = window.setTimeout(() => {
cooldownRef.current = false;
setValue(value);
}, wait);
}
}
}, [value, options.leading, wait]);
useEffect(() => {
mountedRef.current = true;
return cancel;
}, []);
return [_value, cancel];
}
export { useDebouncedValue };
//# sourceMappingURL=use-debounced-value.mjs.map