Skip to content
On this page

useInterval

Reactive counter increases on every interval

Demo

Category
Last Changed
last month

Interval fired: 0

Usage




 





import { useInterval } from '@vueuse/core'

// count will increase every 200ms
const counter = useInterval(200)
import { useInterval } from '@vueuse/core'

// count will increase every 200ms
const counter = useInterval(200)
const { counter, pause, resume } = useInterval(200, { controls: true })
const { counter, pause, resume } = useInterval(200, { controls: true })

Type Declarations

export interface UseIntervalOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Exccute the update immediately on calling
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Reactive counter increases on every interval
 *
 * @see https://vueuse.org/useInterval
 */
export declare function useInterval(
  interval?: MaybeComputedRef<number>,
  options?: UseIntervalOptions<false>
): Ref<number>
export declare function useInterval(
  interval: MaybeComputedRef<number>,
  options: UseIntervalOptions<true>
): {
  counter: Ref<number>
} & Pausable
export interface UseIntervalOptions<Controls extends boolean> {
  /**
   * Expose more controls
   *
   * @default false
   */
  controls?: Controls
  /**
   * Exccute the update immediately on calling
   *
   * @default true
   */
  immediate?: boolean
}
/**
 * Reactive counter increases on every interval
 *
 * @see https://vueuse.org/useInterval
 */
export declare function useInterval(
  interval?: MaybeComputedRef<number>,
  options?: UseIntervalOptions<false>
): Ref<number>
export declare function useInterval(
  interval: MaybeComputedRef<number>,
  options: UseIntervalOptions<true>
): {
  counter: Ref<number>
} & Pausable

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
Nurettin Kaya

Changelog

v9.0.0-beta.1 on 7/20/2022
43732 - fix!: rename type IntervalOptions to UseIntervalOptions (#1945)

Released under the MIT License.