UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

20 lines (19 loc) 846 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useThrottledState = void 0; var __1 = require(".."); /** * Like `useSafeState` but its state setter is throttled. * * @param initialState Initial state to pass to underlying `useSafeState`. * @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 useThrottledState(initialState, delay, noTrailing) { if (noTrailing === void 0) { noTrailing = false; } var _a = (0, __1.useSafeState)(initialState), state = _a[0], setState = _a[1]; return [state, (0, __1.useThrottledCallback)(setState, [], delay, noTrailing)]; } exports.useThrottledState = useThrottledState;