diff --git a/web/components/auto-refresh.tsx b/web/components/auto-refresh.tsx new file mode 100644 index 0000000..61d60b4 --- /dev/null +++ b/web/components/auto-refresh.tsx @@ -0,0 +1,24 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; + +/** + * Mounts a setInterval that calls router.refresh() every `intervalMs`. + * router.refresh() re-runs the matching Server Component fetch and + * patches the rendered output in — no full page reload, no flicker. + * + * Renders nothing. + */ +export default function AutoRefresh({ + intervalMs = 30_000, +}: { + intervalMs?: number; +}) { + const router = useRouter(); + useEffect(() => { + const id = setInterval(() => router.refresh(), intervalMs); + return () => clearInterval(id); + }, [router, intervalMs]); + return null; +}