feat: add custom next-remote-watch

This commit is contained in:
Timothy Lin
2021-10-17 16:13:09 +08:00
parent 82e74ba391
commit cc2ecb1c3b
5 changed files with 355 additions and 1 deletions

View File

@ -0,0 +1,23 @@
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()
socket.on('reload', (data) => {
Router.replace(Router.asPath, undefined, {
scroll: false,
})
})
})
}, [])
return null
}