mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 10:32:19 -05:00
16 lines
399 B
TypeScript
16 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
|
||
|
}
|