Skip to content

useIntervalFn

Category
Export Size
341 B
Last Changed
5 months ago

Wrapper for setInterval with controls

Demo

Salut!

interval:

Usage

js
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 immediately after calling `resume`
   *
   * @default false
   */
  immediateCallback?: boolean
}
/**
 * Wrapper for `setInterval` with controls
 *
 * @param cb
 * @param interval
 * @param options
 */
export declare function useIntervalFn(
  cb: Fn,
  interval?: MaybeRefOrGetter<number>,
  options?: UseIntervalFnOptions,
): Pausable

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
Lapor Chen
Anthony Fu
Börge Kiss
Dan Rose
sun0day
Enzo Innocenzi
wwj
Matvey Melishev
meteorlxy
Aurélio A. Heckert
xuxuhahaha
Hogne Vevle
Daiki Ojima

Changelog

v11.2.0 on 10/30/2024
59f8c - fix: prevent timer being set after pause is called in cb (#4258)
v10.0.0-beta.5 on 4/13/2023
cb644 - refactor!: remove isFunction and isString utils
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue
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)

Released under the MIT License.

SUPER SALE
Get a yearly plan for a massive 50% OFF
+ 2 Masterclass Courses + Free Workshop
Get Offer
Extended for
01
hours
:
51
minutes
:
21
seconds
: