auto-refresh.tsx21 lines · main
| 1 | 'use client'; |
| 2 | import { useRouter } from 'next/navigation'; |
| 3 | import { useEffect } from 'react'; |
| 4 | |
| 5 | export function AutoRefresh({ active }: { active: boolean }) { |
| 6 | const router = useRouter(); |
| 7 | useEffect(() => { |
| 8 | if (!active) return; |
| 9 | const id = setInterval(() => router.refresh(), 5000); |
| 10 | return () => clearInterval(id); |
| 11 | }, [active, router]); |
| 12 | if (!active) return null; |
| 13 | return ( |
| 14 | <p className="mt-4 font-mono text-[10px] text-[var(--color-primary)] text-center"> |
| 15 | <span className="inline-block w-1.5 h-1.5 rounded-full bg-[var(--color-primary)] animate-pulse mr-1.5 align-middle" /> |
| 16 | updates in real time |
| 17 | </p> |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 |