UNPKG

@yukimoto/use-clamp-text

Version:

This package provide a custome hook that can limit the text in the container in specified line number.

25 lines (24 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDebounce = void 0; var lodash_1 = require("lodash"); var react_1 = require("react"); /** * Enhanced debounce hook, from https://github.com/imbhargav5/rooks/blob/main/src/hooks/useDebounce.ts * @param callback The callback function to debounce * @param wait The duration to debounce in milisecond * @param options DebounceSettings from lodash * @returns Returns the debounced function. */ var useDebounce = function (callback, wait, options) { var createDebouncedCallback = (0, react_1.useCallback)(function (cb) { return (0, lodash_1.debounce)(cb, wait, options); }, [wait, options]); var debouncedCallbackRef = (0, react_1.useRef)(createDebouncedCallback(callback)); (0, react_1.useEffect)(function () { debouncedCallbackRef.current = createDebouncedCallback(callback); return function () { return debouncedCallbackRef.current.cancel(); }; }, [callback, createDebouncedCallback]); return debouncedCallbackRef.current; }; exports.useDebounce = useDebounce;