Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
import { useRef, useEffect } from "react";
const useDebounce = () => {
const timeout = useRef<number | undefined>(400);
const debounce =
(func: Function, wait: number = 0) =>
(...args: any[]) => {
clearTimeout(timeout.current);
timeout.current = window.setTimeout(() => func(...args), wait);
};
useEffect(() => {
return () => {
if (!timeout.current) return;
clearTimeout(timeout.current);
};
}, []);
return { debounce };
};
export default useDebounce;