export default function useDebounce(func: any, delay: number) {
  let timeoutId: NodeJS.Timeout | undefined = undefined;

  return function (...args: any) {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => {
      func.apply(this, args);
    }, delay);
  };
}

let timeoutGlobalId: NodeJS.Timeout | undefined = undefined;

export function useGlobalDebounce(func: any, delay: number) {
  return function (...args: any) {
    clearTimeout(timeoutGlobalId);
    timeoutGlobalId = setTimeout(() => {
      func.apply(this, args);
    }, delay);
  };
}
