useCounter
State & dataA lightweight, type-safe React hook for counter state management
Install
$ npm install @usefy/use-counterQuick start
useCounter.tsx
import { useCounter } from "@usefy/use-counter";
function Counter() {
const { count, increment, decrement, reset } = useCounter(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>+</button>
<button onClick={decrement}>-</button>
<button onClick={reset}>Reset</button>
</div>
);
}API reference
useCounter(initialValue?)
A hook that manages counter state with increment, decrement, and reset capabilities.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
initialValue | number | 0 | The initial value of the counter |
Returns
| Property | Type | Description |
|---|---|---|
count | number | The current counter value |
increment | () => void | Increases the counter by 1 |
decrement | () => void | Decreases the counter by 1 |
reset | () => void | Resets the counter to the initial value |
Go deeper
This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.