UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

25 lines (24 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useThrottledEffect = void 0; /* eslint-disable @typescript-eslint/no-explicit-any */ var react_1 = require("react"); var __1 = require(".."); /** * Like `useEffect`, but passed function is throttled. * * @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 `useThrottledCallback`. * @param delay Throttle delay. * @param noTrailing If `noTrailing` is true, callback will only execute every * `delay` milliseconds, otherwise, callback will be executed one final time * after the last throttled-function call. */ function useThrottledEffect(callback, deps, delay, noTrailing) { if (noTrailing === void 0) { noTrailing = false; } // eslint-disable-next-line react-hooks/exhaustive-deps (0, react_1.useEffect)((0, __1.useThrottledCallback)(callback, deps, delay, noTrailing), deps); } exports.useThrottledEffect = useThrottledEffect;