Skip to content
On this page

useIntervalFn

Category
Last Changed
25 days ago

Wrapper for setInterval with controls

Demo

Hello

interval:

Usage

import { useIntervalFn } from '@vueuse/core'

const { pause, resume, isActive } = useIntervalFn(() => {
  /* your function */
}, 1000)
import { useIntervalFn } from '@vueuse/core'

const { pause, resume, isActive } = useIntervalFn(() => {
  /* your function */
}, 1000)

Type Declarations

export interface IntervalFnOptions {
  /**
   * Start the timer immediately
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Execute the callback immediate after calling this function
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * Wrapper for `setInterval` with controls
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useIntervalFn(
  cb: Fn,
  interval?: MaybeRef<number>,
  options?: IntervalFnOptions
): Pausable
export interface IntervalFnOptions {
  /**
   * Start the timer immediately
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Execute the callback immediate after calling this function
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * Wrapper for `setInterval` with controls
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useIntervalFn(
  cb: Fn,
  interval?: MaybeRef<number>,
  options?: IntervalFnOptions
): Pausable

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
Hogne Vevle
Daiki Ojima

Changelog

v7.6.0 on 2/8/2022
a2b2b - feat(useInterval): support ref as interval (#1215)
v6.0.0-beta.2 on 8/9/2021
ff21b - feat: use tryOnScopeDispose instead of tryOnUnmounted
v5.2.0 on 7/25/2021
4fc34 - feat: new option immediateCallback (#639)
useIntervalFn has loaded