useCounter is a React hook that manages a numeric counter state with increment, decrement, and reset capabilities. Optionally, you can provide minimum and maximum values to constrain the counter's range.
function useCounter(options: UseCounterOptions): UseCounterReturn;import { useCounter } from 'react-simplikit';
function ShoppingCart() {
const { count, increment, decrement, reset } = useCounter({
initialValue: 1,
min: 1,
max: 10,
});
return (
<div>
<span>Quantity: {count}</span>
<button type="button" onClick={decrement}>
-
</button>
<button type="button" onClick={increment}>
+
</button>
<button type="button" onClick={reset}>
Reset
</button>
</div>
);
}