diff --git a/packages/react/src/ThebeServerProvider.tsx b/packages/react/src/ThebeServerProvider.tsx index ae18bd2a..a7e79a16 100644 --- a/packages/react/src/ThebeServerProvider.tsx +++ b/packages/react/src/ThebeServerProvider.tsx @@ -13,13 +13,13 @@ type ListenerFn = (data: ThebeEventData) => void; export const ThebeServerContext = React.createContext< | { + connecting: boolean; + ready: boolean; config?: Config; events?: ThebeEvents; server?: ThebeServer; - connecting: boolean; - ready: boolean; - connect: () => void; - disconnect: () => Promise; + connect?: () => void; + disconnect?: () => Promise; } | undefined >(undefined); @@ -144,7 +144,10 @@ export function useThebeServer() { const { core } = thebe ?? {}; const serverContext = useContext(ThebeServerContext); - const { config, events, server, connecting, ready, connect, disconnect } = serverContext ?? {}; + const { config, events, server, connecting, ready, connect, disconnect } = serverContext ?? { + ready: false, + connecting: false, + }; const [error, setError] = useState(); // TODO how to handle errors better via the provider const [eventCallbacks, setEventCallbacks] = useState([]); @@ -192,5 +195,5 @@ export function useThebeServer() { subscribe, unsubAll, } - : {}; + : { connecting: false, ready: false }; } diff --git a/packages/react/src/ThebeSessionProvider.tsx b/packages/react/src/ThebeSessionProvider.tsx index d32ee9bb..ee2c082a 100644 --- a/packages/react/src/ThebeSessionProvider.tsx +++ b/packages/react/src/ThebeSessionProvider.tsx @@ -7,8 +7,8 @@ interface ThebeSessionContextData { path?: string; session?: ThebeSession; error?: string; - starting?: boolean; - ready?: boolean; + starting: boolean; + ready: boolean; start?: () => Promise; shutdown?: () => Promise; } @@ -104,5 +104,5 @@ export function ThebeSessionProvider({ export function useThebeSession(): ThebeSessionContextData { const sessionContext = useContext(ThebeSessionContext); - return sessionContext ?? {}; + return sessionContext ?? { starting: false, ready: false }; }