Skip to content

useCounter

Create a counter with increment, decrement, set, and reset actions.

Usage

const App = () => {
const [count, { increment, decrement, set, reset }] = useCounter(5, {
min: 0,
max: 10,
});
return (
<div>
<p>{count}</p>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
<button onClick={() => set(5)}>Set to 5</button>
<button onClick={() => reset()}>Reset</button>
</div>
);
};

Installation

Terminal window
npx atmx add hook use-counter