@react-hookz/web
Version:
React hooks done right, for browser and SSR.
19 lines (18 loc) • 762 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDebouncedState = void 0;
var __1 = require("..");
/**
* Like `useSafeState` but its state setter is debounced.
*
* @param initialState Initial state to pass to underlying `useSafeState`.
* @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 useDebouncedState(initialState, delay, maxWait) {
if (maxWait === void 0) { maxWait = 0; }
var _a = (0, __1.useSafeState)(initialState), state = _a[0], setState = _a[1];
return [state, (0, __1.useDebouncedCallback)(setState, [], delay, maxWait)];
}
exports.useDebouncedState = useDebouncedState;