import { useCallback, useRef } from 'react'; export const useDebounce = () => { const _timer = useRef(); const withDebounce = useCallback((cb: () => void, ms: number) => { if (_timer.current) { clearTimeout(_timer.current); } _timer.current = setTimeout(cb, ms); }, []); return { withDebounce, }; };