Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useTimer

A reactive timer composable with pause/resume support and remaining time tracking.


IntermediateApr 5, 2026

Usage

The useTimer composable creates a controllable timer that fires a handler after a specified duration. It supports pause/resume, repeating intervals, and reactive remaining time tracking.

ts
import { useTimer } from '@vuetify/v0'

const timer = useTimer(() => {
  console.log('Timer fired!')
}, { duration: 5000 })

// Control the timer
timer.start()
timer.pause()
timer.resume()
timer.stop()

// Reactive state
timer.remaining.value  // ms left until next fire
timer.isActive.value   // true when started (even if paused)
timer.isPaused.value   // true when paused
Tip

Replaces debounce useTimer replaces the deprecated debounce utility. It provides the same delay behavior with pause/resume, repeat support, and automatic cleanup on scope disposal.

Architecture

useTimer Lifecycle

Use controls to zoom and pan. Click outside or press Escape to close.

useTimer Lifecycle

The timer tracks three internal values: startedAt (timestamp when the current run began), budget (remaining ms for the current run), and duration (the original interval). On pause, budget is reduced by elapsed time. On resume, a new setTimeout is created with the remaining budget.

Reactivity

PropertyTypeDescription
remainingShallowRef<number>Milliseconds until next fire, updated ~100ms
isActiveShallowRef<boolean>true after start(), false after stop() or one-shot fires
isPausedShallowRef<boolean>true after pause(), false after resume() or stop()

Examples

Countdown

A 10-second countdown timer demonstrating all four controls — start, stop, pause, resume — with a progress bar driven by the reactive remaining value.

10s
Ready
isActive: false
isPaused: false
10000ms

Toast Notifications

Auto-dismissing notifications where each toast owns its own useTimer. Hovering a toast pauses its countdown, and the progress bar reflects the remaining time.

FileRole
useToast.tsToast state — reactive array with add/dismiss helpers
Toast.vueSingle toast — owns a useTimer, pauses on hover
toasts.vueEntry point — trigger buttons and toast list

Hover a toast to pause its countdown

Key Features

One-Shot vs Repeating

By default, the timer fires once and stops. Set repeat: true for an interval that restarts after each fire:

ts
// One-shot (default) — fires once, then isActive becomes false
const delay = useTimer(() => save(), { duration: 3000 })

// Repeating — fires every 5 seconds until stopped
const poll = useTimer(() => refresh(), { duration: 5000, repeat: true })

Pause and Resume

Pause preserves the remaining time. Resume continues from where it left off:

ts
const timer = useTimer(handler, { duration: 10_000 })
timer.start()

// After 3 seconds...
timer.pause()
// remaining.value ≈ 7000

// Later...
timer.resume()
// fires after ~7 more seconds

Restart Behavior

Calling start() while already running restarts from full duration:

ts
timer.start()  // starts 5s countdown
// 2 seconds later...
timer.start()  // restarts — fires in 5s, not 3s

Automatic Cleanup

The timer clears on scope disposal — no manual cleanup needed:

ts
// Timer automatically stops when component unmounts
const timer = useTimer(handler, { duration: 1000 })

API Reference

The following API details are for the useTimer composable.

Functions

useTimer

(handler: () => void, options?: TimerOptions) => TimerContext

Creates a reactive timer with pause/resume support.

Options

duration

number | undefined

Duration in milliseconds.

Default: 1000

repeat

boolean | undefined

Whether the timer repeats after firing.

Default: false

Properties

remaining

ShallowRef<number>

Milliseconds left until next fire.

isActive

ShallowRef<boolean>

Whether the timer is currently active (started and not stopped).

isPaused

ShallowRef<boolean>

Whether the timer is currently paused.

Methods

start

() => void

Start the timer. Restarts if already running.

stop

() => void

Stop the timer and reset remaining to full duration.

pause

() => void

Pause the timer, preserving remaining time. No-op if not running.

resume

() => void

Resume from where pause left off. No-op if not paused.

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/