Skip to content

Instantly share code, notes, and snippets.

@akshitkrnagpal
Last active April 16, 2025 19:47
Show Gist options
  • Save akshitkrnagpal/4684b1d7f40deeb5f5bff657e1d4feee to your computer and use it in GitHub Desktop.
Save akshitkrnagpal/4684b1d7f40deeb5f5bff657e1d4feee to your computer and use it in GitHub Desktop.
RSC - Polling
import { RSCPolling } from "./rsc-polling";
export const DataFetcher = async () => {
const { status, data } = await getData();
if (status === "processing") {
return <RSCPolling interval={1000} />;
}
return <DataViewer data={data} />;
};
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
export const RSCPolling = ({ interval }: { interval: number }) => {
const router = useRouter();
useEffect(() => {
const ref = setInterval(() => {
router.refresh();
}, interval);
return () => {
clearInterval(ref);
};
}, []);
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment