import { EffectCallback } from 'react'; export declare type TimerHookStatus = 'idle' | 'running' | 'paused' | 'expired'; export interface TimerHook { /** * Starts the timer. If the timer is currently in a paused state, then it will * resume based on the original remaining length. */ start: () => void; /** * Pauses the timer. This function has no effect if the timer has not yet * started ticking. */ pause: () => void; /** * Resumes the timer. This function has no effect if the timer has not yet * started ticking. */ resume: () => void; /** * Restarts the timer with new parameters. * * @param newLength - Optionally provide a new timer length (in milliseconds). * @param newTick - Optionally provide a new tick length (in milliseconds). */ restart: (options?: RestartTimerOptions) => void; /** * A function returning the amount of time (in milliseconds) remaining in the * timer. If the timer is idle, this function returns `0`. */ getRemaining: () => number; /** * A function returning the number of ticks that have accumulated since the * start of the currently-running timer. */ getTickCount: () => number; /** * Returns a string enum indicating the current timer state * (one of: `"idle"`, `"running"`, `"paused"`, or `"expired"`). */ getStatus: () => TimerHookStatus; /** * A static value that updates whenever the underlying timer state changes. * You can give this value to the dependency list `React.useEffect` to trigger * an effect. */ key: number; } export interface RestartTimerOptions { length?: number; tick?: number; } export interface UseTimerOptions { length: number; tick?: number; autoStart?: boolean; } /** * Returns a timer that works inside the React lifecycle. * * @param length - The total length of the timer (in milliseconds). * @param tick - The interval at which to update the timer (in milliseconds). * @param autoStart - If `true`, the timer will immediately start ticking using * the initially-provided `length` and `tick` values. */ export declare function useTimer(options: UseTimerOptions): TimerHook; /** * Execute an effect if the supplied timer ticks. * * @param timer - The `TimerHook` object from which to trigger the effect. * @param effect - Imperative function that can return a cleanup function. */ export declare function useTimerTick(timer: TimerHook, effect: EffectCallback): void; /** * Execute an effect if the supplied timer expires (completes its countdown). * * @param timer - The `TimerHook` object from which to trigger the effect. * @param effect - Imperative function that can return a cleanup function. */ export declare function useTimerExpire(timer: TimerHook, effect: EffectCallback): void;