react-timer-hook
Version:
React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.
16 lines (15 loc) • 584 B
TypeScript
import { TimeFromMillisecondsType } from './utils/Time';
export type useTimerSettingsType = {
expiryTimestamp: Date;
onExpire?: () => void;
autoStart?: boolean;
interval?: number;
};
export type useTimerResultType = TimeFromMillisecondsType & {
start: () => void;
pause: () => void;
resume: () => void;
restart: (newExpiryTimestamp: Date, newAutoStart?: boolean) => void;
isRunning: boolean;
};
export default function useTimer({ expiryTimestamp: expiry, onExpire, autoStart, interval: customInterval, }: useTimerSettingsType): useTimerResultType;