UNPKG

@theoplayer/react-native-ui

Version:

A React Native UI for @theoplayer/react-native

17 lines 502 B
import { useCallback, useRef } from 'react'; export function useDebouncedCallback(func, delay) { const timeoutRef = useRef(undefined); return useCallback((value, force) => { clearTimeout(timeoutRef.current); timeoutRef.current = undefined; if (force) { func(value); } else { timeoutRef.current = setTimeout(() => { timeoutRef.current = undefined; func(value); }, delay); } }, [func, delay]); } //# sourceMappingURL=useDebouncedCallback.js.map