mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-23 22:53:58 +00:00
23e2d9bf99
GitOrigin-RevId: 3c93491041170cd78c66bc0ab5db516749f9eded
16 lines
473 B
TypeScript
16 lines
473 B
TypeScript
import { useEffect } from 'react'
|
|
import { useUserChannel } from './use-user-channel'
|
|
|
|
export const useReceiveUser = (
|
|
handleData: (data: Record<string, any>) => void
|
|
) => {
|
|
const channel = useUserChannel()
|
|
|
|
useEffect(() => {
|
|
const abortController = new AbortController()
|
|
channel?.addEventListener('message', ({ data }) => handleData(data), {
|
|
signal: abortController.signal,
|
|
})
|
|
return () => abortController.abort()
|
|
}, [channel, handleData])
|
|
}
|