UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

24 lines (23 loc) 984 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDebouncedEffect = void 0; /* eslint-disable @typescript-eslint/no-explicit-any */ var react_1 = require("react"); var __1 = require(".."); /** * Like `useEffect`, but passed function is debounced. * * @param callback Callback like for `useEffect`, but without ability to return * a cleanup function. * @param deps Dependencies list that will be passed to underlying `useEffect` * and `useDebouncedCallback`. * @param delay Debounce delay. * @param maxWait Maximum amount of milliseconds that function can be delayed * before it's force execution. 0 means no max wait. */ function useDebouncedEffect(callback, deps, delay, maxWait) { if (maxWait === void 0) { maxWait = 0; } // eslint-disable-next-line react-hooks/exhaustive-deps (0, react_1.useEffect)((0, __1.useDebouncedCallback)(callback, deps, delay, maxWait), deps); } exports.useDebouncedEffect = useDebouncedEffect;