@thibault.sh/hooks
Version: 
A comprehensive collection of React hooks for browser storage, UI interactions, and more
32 lines (30 loc) • 1.15 kB
text/typescript
/**
 * Hook that creates a countdown timer to a target date with automatic updates.
 *
 * Provides real-time countdown values that update at a specified interval.
 * Returns zero values when the target date has passed.
 *
 * @param countDownDate - Target date as a timestamp in milliseconds (e.g., `new Date('2024-12-31').getTime()`)
 * @param refreshRate - Update interval in milliseconds (defaults to 1000ms for 1-second updates)
 *
 * @returns A readonly tuple `[days, hours, minutes, seconds]` representing time remaining
 *
 * @example
 * ```tsx
 * const targetDate = new Date('2024-12-31 23:59:59').getTime();
 * const [days, hours, minutes, seconds] = useCountdown(targetDate);
 *
 * return (
 *   <div>
 *     {days}d {hours}h {minutes}m {seconds}s remaining
 *   </div>
 * );
 * ```
 *
 * @example
 * // Custom refresh rate (every 100ms for smoother animation)
 * const [days, hours, minutes, seconds] = useCountdown(targetDate, 100);
 * @see https://thibault.sh/hooks/use-countdown
 */
declare function useCountdown(countDownDate: number, refreshRate?: number): number[] | readonly [number, number, number, number];
export { useCountdown };