mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 15:02:25 -05:00
23e2d9bf99
GitOrigin-RevId: 3c93491041170cd78c66bc0ab5db516749f9eded
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
|
|
}
|