import { useEffect } from "react";

export function useDebouncedEffect(effect, deps, delay = 300) {
  useEffect(() => {
    let cleanup;
    const handle = window.setTimeout(() => {
      cleanup = effect();
    }, delay);
    return () => {
      window.clearTimeout(handle);
      if (typeof cleanup === "function") cleanup();
    };
  }, deps);
}
