Context.tsx26 lines · main
1'use client'
2
3import { createContext, useContext } from 'react'
4
5import { type IPagesState } from '../internal/state/pagesState'
6import { type IQueryState } from '../internal/state/queryState'
7import { type IViewState } from '../internal/state/viewState.types'
8import { type ICommandsState } from '../internal/types'
9
10const CommandContext = createContext<
11 | {
12 commandsState: ICommandsState
13 pagesState: IPagesState
14 queryState: IQueryState
15 viewState: IViewState
16 }
17 | undefined
18>(undefined)
19
20const useCommandContext = () => {
21 const ctx = useContext(CommandContext)
22 if (!ctx) throw Error('`useCommandContext` must be used within a `CommandProvider`')
23 return ctx
24}
25
26export { CommandContext, useCommandContext }