Last active
October 17, 2022 12:09
-
-
Save marvinkome/77a0671e1802a3c8b54dc19bc5d2056e to your computer and use it in GitHub Desktop.
nextjs refetch page 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
| import Router from "next/router"; | |
| // How to refresh server data without reloading the page | |
| // https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/ | |
| // https://twitter.com/flybayer/status/1333081016995622914 | |
| export function refetchPageData(path: string) { | |
| return new Promise<void>((res, rej) => { | |
| Router.events.on("routeChangeComplete", () => { | |
| res(); | |
| }); | |
| setTimeout(() => { | |
| rej("Reload timeout"); | |
| }, 5000); | |
| Router.replace(path); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment