CoverageCheck / web /src /hooks /chatContext.ts
TBM99's picture
Deploy coverage-check 3559250
23d418f verified
Raw History Blame Contribute Delete
758 Bytes
import { createContext, useContext } from 'react'
import type { SystemId } from '@/lib/types'
import type { useChat } from './useChat'
/** What ChatProvider shares with the pages: the conversation (useChat) and the box's
* settings. In its own file: a file that exports a component should export only
* components (Vite fast refresh). */
export type ChatState = ReturnType<typeof useChat> & {
system: SystemId
setSystem: (s: SystemId) => void
day: string | null
setDay: (d: string | null) => void
}
export const ChatContext = createContext<ChatState | null>(null)
export function useChatContext(): ChatState {
const state = useContext(ChatContext)
if (!state) throw new Error('useChatContext needs a ChatProvider above it')
return state
}