Skip to content
On this page

useCounter

A hook that manage counter.

Code demonstration

API

const [current, { inc, dec, set, reset }] = useCounter(initialValue, { min, max })
const [current, { inc, dec, set, reset }] = useCounter(initialValue, { min, max })

Result

PropertyDescriptionType
currentCurrent valueReadonly<Ref<number>>
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-

Source

SourceDocsDemo