2024-01-15 12:33:15 +00:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import { useRouter } from 'next/navigation'
|
2024-03-04 14:48:40 +00:00
|
|
|
import { ReactNode, useEffect } from 'react'
|
2024-01-15 12:33:15 +00:00
|
|
|
|
2024-03-04 14:48:40 +00:00
|
|
|
let AutoRefresh = ({ children }: { children: ReactNode }) => {
|
2024-01-15 12:33:15 +00:00
|
|
|
return children
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
AutoRefresh = function AutoRefresh({ children }) {
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const ws = new WebSocket('ws://localhost:3201')
|
|
|
|
ws.onmessage = (event) => {
|
|
|
|
if (event.data === 'refresh') {
|
|
|
|
router.refresh()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return () => {
|
|
|
|
ws.close()
|
|
|
|
}
|
|
|
|
}, [router])
|
2024-01-25 23:05:49 +00:00
|
|
|
|
2024-01-15 12:33:15 +00:00
|
|
|
return children
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AutoRefresh
|