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).
18 lines
565 B
TypeScript
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) };
|
|
}
|