import React , { createContext , useContext } from 'react' ; import { StatefulChatClient } from '@internal/chat-stateful-client' ; private export const ChatClientContext = createContext < StatefulChatClient | undefined > ( undefined ) ; /**
 * Arguments to initialize a  ChatClientProvider .
 *
 *  public export type ChatClientProviderProps = { children : React . ReactNode ; chatClient : StatefulChatClient ; } ; /**
 * A  React . Context that stores a  StatefulChatClient .
 *
 * Chat components from this package must be wrapped with a  ChatClientProvider .
 *
 *  public export const ChatClientProvider = ( props ) : JSX . Element => { return < ChatClientContext . Provider value = { props . chatClient } > { props . children } < /ChatClientContext.Provider>; } ; /**
 * Hook to obtain  StatefulChatClient from the provider.
 *
 * Useful when implementing a custom component that utilizes the providers
 * exported from this library.
 *
 *  public export const useChatClient = ( ) : StatefulChatClient => { const chatClient = useContext ( ChatClientContext ) ; if ( ! chatClient ) { throw 'Please wrap components with ChatClientProvider and initialize a chat client before calling the hook!' ; } return chatClient ; } ;