2022-10-17 23:37:01 +08:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import Router from 'next/router';
|
2022-07-17 21:40:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Client-side complement to next-remote-watch
|
|
|
|
* Re-triggers getStaticProps when watched mdx files change
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const ClientReload = () => {
|
|
|
|
// Exclude socket.io from prod bundle
|
|
|
|
useEffect(() => {
|
|
|
|
import('socket.io-client').then((module) => {
|
2022-10-17 23:37:01 +08:00
|
|
|
const socket = module.io();
|
2022-10-07 13:55:39 +08:00
|
|
|
socket.on('reload', () => {
|
2022-07-17 21:40:41 +08:00
|
|
|
Router.replace(Router.asPath, undefined, {
|
|
|
|
scroll: false,
|
2022-10-17 23:37:01 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, []);
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2022-10-17 23:37:01 +08:00
|
|
|
return null;
|
|
|
|
};
|