UNPKG

@theoplayer/react-native-ui

Version:

A React Native UI for @theoplayer/react-native

23 lines (22 loc) 638 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDebouncedCallback = useDebouncedCallback; var _react = require("react"); function useDebouncedCallback(func, delay) { const timeoutRef = (0, _react.useRef)(undefined); return (0, _react.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