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