ghp / packages /client /src /providers /socket-context.ts
QSLY's picture
deploy: build Hugging Face Space from source
00a912e
Raw
History Blame Contribute Delete
469 Bytes
import { createContext, useContext } from 'react'
import type { TypedSocket } from '@/lib/socket'
export interface SocketContextValue {
socket: TypedSocket
isConnected: boolean
}
export const SocketContext = createContext<SocketContextValue | null>(null)
export function useSocketContext(): SocketContextValue {
const context = useContext(SocketContext)
if (!context) throw new Error('useSocketContext must be used within SocketProvider')
return context
}