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

PropertyDescriptionType
currentCurrent valuenumber
incIncrement, default delta is 1(delta?: number) => void
decDecrement, default delta is 1(delta?: number) => void
setSet current value(value: number | ((c: number) => number)) => void
resetReset current value to initial value() => void

Params

PropertyDescriptionTypeDefault
initialValueInitial countnumber0
minMin countnumber-
maxMax countnumber-

On this page