shadcn-ahooks

useCounter

A hook that manage counter.

Overview

A hook that manage counter.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useCounter.json

A 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 | - |

On this page