mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-01 02:04:24 +00:00
15 lines
399 B
TypeScript
15 lines
399 B
TypeScript
import { useEffect, useRef } from 'react'
|
|
|
|
export const useUserChannel = (): BroadcastChannel | null => {
|
|
const channelRef = useRef<BroadcastChannel | null>(null)
|
|
|
|
if (channelRef.current === null && 'BroadcastChannel' in window) {
|
|
channelRef.current = new BroadcastChannel('user')
|
|
}
|
|
|
|
useEffect(() => {
|
|
return () => channelRef.current?.close()
|
|
}, [])
|
|
|
|
return channelRef.current
|
|
}
|