Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useInterval.md
1---2category: Animation3---45# useInterval67Reactive counter that increases on every interval.89## Usage1011```ts12import { useInterval } from '@vueuse/core'1314// count will increase every 200ms15const counter = useInterval(200)16```1718### With Controls1920```ts21import { useInterval } from '@vueuse/core'2223const { counter, reset, pause, resume, isActive } = useInterval(200, {24controls: true,25})2627// Reset counter to 028reset()2930// Pause/resume the interval31pause()32resume()33```3435### Options3637| Option | Type | Default | Description |38| ----------- | ------------------------- | ------- | ---------------------------------------------------------- |39| `controls` | `boolean` | `false` | Expose `pause`, `resume`, `reset`, and `isActive` controls |40| `immediate` | `boolean` | `true` | Start the interval immediately |41| `callback` | `(count: number) => void` | — | Called on every interval with the current count |4243### Reactive Interval4445The interval can be reactive:4647```ts48import { useInterval } from '@vueuse/core'4950const intervalMs = ref(1000)51const counter = useInterval(intervalMs)5253// Change the interval dynamically54intervalMs.value = 50055```5657### Callback on Every Interval5859```ts60import { useInterval } from '@vueuse/core'6162useInterval(1000, {63callback: (count) => {64console.log(`Tick ${count}`)65},66})67```6869## Type Declarations7071```ts72export interface UseIntervalOptions<Controls extends boolean> {73/**74* Expose more controls75*76* @default false77*/78controls?: Controls79/**80* Execute the update immediately on calling81*82* @default true83*/84immediate?: boolean85/**86* Callback on every interval87*/88callback?: (count: number) => void89}90export interface UseIntervalControls {91counter: ShallowRef<number>92reset: () => void93}94export type UseIntervalReturn =95| Readonly<ShallowRef<number>>96| Readonly<UseIntervalControls & Pausable>97/**98* Reactive counter increases on every interval99*100* @see https://vueuse.org/useInterval101* @param interval102* @param options103*/104export declare function useInterval(105interval?: MaybeRefOrGetter<number>,106options?: UseIntervalOptions<false>,107): Readonly<ShallowRef<number>>108export declare function useInterval(109interval: MaybeRefOrGetter<number>,110options: UseIntervalOptions<true>,111): Readonly<UseIntervalControls & Pausable>112```113