File size: 469 Bytes
00a912e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
}