// src/hooks/useDebounce.tsx
import { debounce } from "lodash-es";
import { useEffect, useState } from "react";
function useDebounce(value, delay = 0, options) {
  const [current, setCurrent] = useState(value);
  const jsonOptions = JSON.stringify(options);
  useEffect(() => {
    const debounced = debounce(
      () => {
        setCurrent(value);
      },
      delay,
      options
    );
    debounced();
    return () => {
      debounced.cancel();
    };
  }, [value, delay, jsonOptions]);
  return current;
}

export {
  useDebounce
};
