2022-07-17 21:40:41 +08:00
|
|
|
import { useEffect } from 'react'
|
|
|
|
import Router from 'next/router'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) => {
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|