Skip to content

Instantly share code, notes, and snippets.

@marvinkome
Last active October 17, 2022 12:09
Show Gist options
  • Select an option

  • Save marvinkome/77a0671e1802a3c8b54dc19bc5d2056e to your computer and use it in GitHub Desktop.

Select an option

Save marvinkome/77a0671e1802a3c8b54dc19bc5d2056e to your computer and use it in GitHub Desktop.
nextjs refetch page data
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