mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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
|
||
|
}
|