Skip to content
Clone
2687ace
13 lines 511 B
import { useCallback, useSyncExternalStore } from 'react'
import { voiceSession, type VoiceSessionSnapshot } from './session'
const INITIAL: VoiceSessionSnapshot = voiceSession.getSnapshot()
export function useVoiceSession(): VoiceSessionSnapshot {
const subscribe = useCallback(
(onChange: () => void) => voiceSession.subscribe(() => onChange()),
[],
)
const getSnapshot = useCallback(() => voiceSession.getSnapshot(), [])
return useSyncExternalStore(subscribe, getSnapshot, () => INITIAL)
}