UNPKG

react-native-ui-lib

Version:

[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)

18 lines (17 loc) 451 B
import { useCallback, useRef } from 'react'; /** * This hook is used to debounce a function call */ function useDebounce(func, timeout = 300) { const handler = useRef(); const debouncedFunction = useCallback(args => { if (handler.current) { clearTimeout(handler.current); } handler.current = setTimeout(() => { func(args); }, timeout); }, [func, timeout]); return debouncedFunction; } export default useDebounce;