mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -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
|
||
|
}
|