()
| 6 | // It will reload the content every time the current page is focussed |
| 7 | // (from being not focussed). |
| 8 | export default function ClientSideRefresh() { |
| 9 | const router = useRouter() |
| 10 | |
| 11 | useSWR( |
| 12 | router.asPath, |
| 13 | () => { |
| 14 | // Remember, in NextJS, the `router.locale` is never including the |
| 15 | // `router.asPath`. So we have to make sure it's always there |
| 16 | // otherwise, after this hook runs, you lose that `/en` prefix |
| 17 | // in the URL on the address bar. |
| 18 | router.replace(`/${router.locale}${router.asPath}`, undefined, { scroll: false }) |
| 19 | }, |
| 20 | { |
| 21 | // Implied here is that `revalidateOnFocus: true` which the default |
| 22 | // and it means that the `useSWR` hook will make a listener on the |
| 23 | // the Page Visibility API. |
| 24 | // https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API |
| 25 | // It effectly means that the callback of this hook will run every |
| 26 | // time the browser window is put back to being visible. |
| 27 | |
| 28 | // The `revalidateOnMount` is crucial because it means that we don't |
| 29 | // bother executing the hook callback when it was first mounted |
| 30 | // because, naturally, the first time you mount it, it will not |
| 31 | // need to refresh because it's as fresh as it gets already. |
| 32 | revalidateOnMount: false, |
| 33 | } |
| 34 | ) |
| 35 | |
| 36 | return null |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected