fn

useCounter

v0.0.1testeddemo

A composable that provides a counter with increment, decrement, set, get, and reset functions

Examples

ts
const { count, increment } = useCounter(0);
ts
const { count, increment, decrement, set, get, reset } = useCounter(0, { min: 0, max: 10 });

Demo

Loading demo…

Signature

ts
export function useCounter(
  initialValue: MaybeRefOrGetter<number> = 0,
  options: UseCounterOptions ={ ... }

Parameters

ParameterTypeDescription
initialValue?MaybeRefOrGetter<number>The initial value of the counter
options?UseCounterOptionsThe options for the counter

Returns

UseConterReturnThe counter object
PropertyTypeDescription
countRef<number>
increment(delta?: number) => void
decrement(delta?: number) => void
set(value: number) => void
get() => number
reset(value?: number) => void