Last active
April 16, 2025 19:47
-
-
Save akshitkrnagpal/4684b1d7f40deeb5f5bff657e1d4feee to your computer and use it in GitHub Desktop.
RSC - Polling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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