Appearance
useTimestamp
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