feat: add custom next-remote-watch

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

No files matched your search

+23
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
}