Skip to content
On this page

useIntervalFn

Category
Export Size
394 B
Last Changed
3 weeks ago

Wrapper for setInterval with controls

Demo

Hello

interval:

Usage

js
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

typescript
export interface UseIntervalFnOptions {
  /**
   * 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?: MaybeComputedRef<number>,
  options?: UseIntervalFnOptions
): Pausable
export interface UseIntervalFnOptions {
  /**
   * 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?: MaybeComputedRef<number>,
  options?: UseIntervalFnOptions
): Pausable

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
Dan Rose
sun0day
Enzo Innocenzi
wwj
Matvey Melishev
meteorlxy
Aurélio A. Heckert
xuxuhahaha
Hogne Vevle
Daiki Ojima

Changelog

v9.12.0 on 1/29/2023
39183 - feat(useRafFn, useIntervalFn, useTimeoutFn): make status readonly (#2685)
v9.7.0 on 12/16/2022
8bb7b - fix: watch computed refs instead of just refs (#2539)
v9.0.0-beta.1 on 7/20/2022
4bc0f - fix!: rename type IntervalFnOptions to UseIntervalFnOptions (#1943)
v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)
v8.7.0 on 6/16/2022
16740 - fix: watch interval correctly (#1676)
v8.6.0 on 5/31/2022
29fc5 - fix: unref interval (#1633)
v7.6.0 on 2/8/2022
a2b2b - feat(useInterval): support ref as interval (#1215)

Released under the MIT License.