Files
CIAgent/apps/web/hooks/use-countdown.ts
saksham 1a4c80958f Initial commit: CI Agent competitive-intelligence monitoring app
FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring,
source collection, LLM-based change analysis, enrichment, and account
security (Turnstile, escalating lockout, email verification).
2026-08-05 10:48:20 -04:00

18 lines
565 B
TypeScript

"use client";
import { useEffect, useState } from "react";
/** A countdown in whole seconds, started on demand via `start(seconds)` -
* drives the "Resend in Ns" button state after a 429 throttle response. */
export function useCountdown() {
const [remaining, setRemaining] = useState(0);
useEffect(() => {
if (remaining <= 0) return;
const timer = setTimeout(() => setRemaining((s) => Math.max(0, s - 1)), 1000);
return () => clearTimeout(timer);
}, [remaining]);
return { remaining, start: (seconds: number) => setRemaining(seconds) };
}