overleaf/services/web/frontend/js/shared/hooks/user-channel/use-user-channel.ts
Alf Eaton 23e2d9bf99 Close pop-up window and update UI after reference provider linking (#15106)
GitOrigin-RevId: 3c93491041170cd78c66bc0ab5db516749f9eded
2023-10-09 08:04:04 +00:00

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
}