Skip to content

useCounter

Category
Last Changed
8 months ago

Basic counter with utility functions.

Demo

Count: 0

Basic Usage

import { useCounter } from '@vueuse/core'

const { count, inc, dec, set, reset } = useCounter()
import { useCounter } from '@vueuse/core'

const { count, inc, dec, set, reset } = useCounter()

Usage with options

import { useCounter } from '@vueuse/core'

const { count, inc, dec, set, reset } = useCounter(1, { min: 0, max: 16 })
import { useCounter } from '@vueuse/core'

const { count, inc, dec, set, reset } = useCounter(1, { min: 0, max: 16 })

Type Declarations

export interface UseCounterOptions {
  min?: number
  max?: number
}
/**
 * Basic counter with utility functions.
 *
 * @see https://vueuse.org/useCounter
 * @param [initialValue=0]
 * @param {Object} options
 */
export declare function useCounter(
  initialValue?: number,
  options?: UseCounterOptions
): {
  count: Ref<number>
  inc: (delta?: number) => number
  dec: (delta?: number) => number
  get: () => number
  set: (val: number) => number
  reset: (val?: number) => number
}
export interface UseCounterOptions {
  min?: number
  max?: number
}
/**
 * Basic counter with utility functions.
 *
 * @see https://vueuse.org/useCounter
 * @param [initialValue=0]
 * @param {Object} options
 */
export declare function useCounter(
  initialValue?: number,
  options?: UseCounterOptions
): {
  count: Ref<number>
  inc: (delta?: number) => number
  dec: (delta?: number) => number
  get: () => number
  set: (val: number) => number
  reset: (val?: number) => number
}

Source

SourceDemoDocs

Contributors

Anthony Fu
Damien Roche
Alex Kozack

Changelog

v6.9.2 on 11/19/2021
3c638 - feat: add options (#928)
useCounter has loaded