Skip to content

useTimestamp

Category
Export Size
337 B
Last Changed
5 days ago

Reactive current timestamp (Date.now() + offset), updating on every animation frame

Demo

Usage

tsx
import { 
useTimestamp
} from '@reause/core'
const
timestamp
=
useTimestamp
({
offset
: 0 })
tsx
const { 
timestamp
,
pause
,
resume
} =
useTimestamp
({
controls
: true })

Type Declarations

ts
export interface UseTimestampOptions<Controls extends boolean> {
    controls?: Controls;
    offset?: number;
    callback?: (timestamp: number) => void;
}

export interface UseTimestampControls {
    timestamp: number;
    isActive: boolean;
    pause: () => void;
    resume: () => void;
}

export type UseTimestampReturn<Controls extends boolean> = Controls extends true ? UseTimestampControls : number

export function useTimestamp(options?: UseTimestampOptions<false>): number

export function useTimestamp(options: UseTimestampOptions<true>): UseTimestampControls

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
4f4cc - fix(core): resolve useTimestamp audit findings (#672)

Released under the MIT License. v0.1.8