useCounter
A hook that manage counter.
Overview
A hook that manage counter.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.jsonA hook that manage counter.
Examples
Default usage
API
const [current, {
inc,
dec,
set,
reset
}] = useCounter(initialValue, { min, max });Result
| Property | Description | Type |
| -- | | |
| current | Current value | number |
| inc | Increment, default delta is 1 | (delta?: number) => void |
| dec | Decrement, default delta is 1 | (delta?: number) => void |
| set | Set current value | (value: number | ((c: number) => number)) => void |
| reset | Reset current value to initial value | () => void |
Params
| Property | Description | Type | Default |
| | - | -- | - |
| initialValue | Initial count | number | 0 |
| min | Min count | number | - |
| max | Max count | number | - |