mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04: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
|
||
|
}
|