import { createContext, useContext, useState, ReactNode } from 'react'; import { WebClient } from '@app/websocket'; import { createWebClientRequest, createWebClientResponse } from '@app/api'; export const WebClientContext = createContext(null); export function WebClientProvider({ children }: { children: ReactNode }) { const [client] = useState(() => new WebClient(createWebClientRequest(), createWebClientResponse())); return {children}; } export function useWebClient(): WebClient { const client = useContext(WebClientContext); if (!client) { throw new Error('useWebClient must be used within a WebClientProvider'); } return client; }