feat(web): add 30s auto-refresh client component
This commit is contained in:
parent
b398faba0a
commit
0ebd35f964
24
web/components/auto-refresh.tsx
Normal file
24
web/components/auto-refresh.tsx
Normal file
@ -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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user