@ozen-ui/kit
Version:
React component library
17 lines (16 loc) • 804 B
JavaScript
import { __read } from "tslib";
import { useCallback, useState } from 'react';
export function useCounter(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.initialValue, initialValue = _c === void 0 ? 0 : _c, _d = _b.step, step = _d === void 0 ? 1 : _d;
var _e = __read(useState(initialValue), 2), count = _e[0], setCount = _e[1];
var increment = useCallback(function () { return setCount(function (x) { return x + step; }); }, [step]);
var decrement = useCallback(function () { return setCount(function (x) { return x - step; }); }, [step]);
var reset = useCallback(function () { return setCount(initialValue); }, [initialValue]);
return {
count: count,
increment: increment,
decrement: decrement,
reset: reset,
setCount: setCount,
};
}