-
Notifications
You must be signed in to change notification settings - Fork 3
/
useStudioContext.tsx
27 lines (24 loc) · 1.09 KB
/
useStudioContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { TemplateProps } from '@yext/pages'
import { createContext, useContext, Dispatch, SetStateAction } from 'react'
import { ComponentState, PageState } from '../../shared/models'
import { StudioProps } from './Studio'
export interface StudioContextType {
moduleNameToComponentMetadata: StudioProps['moduleNameToComponentMetadata'],
pageState: PageState,
setPageState: Dispatch<SetStateAction<PageState>>,
siteSettings: StudioProps['siteSettings'],
streamDocument: TemplateProps['document'],
setStreamDocument: Dispatch<SetStateAction<TemplateProps['document']>>,
activeComponentState: ComponentState | undefined,
setActiveComponentState: Dispatch<SetStateAction<ComponentState | undefined>>,
pageStateOnFile: PageState,
setPageStateOnFile: Dispatch<SetStateAction<PageState>>
}
export const StudioContext = createContext<StudioContextType | null>(null)
export function useStudioContext(): StudioContextType {
const studioContext = useContext(StudioContext)
if (studioContext === null) {
throw new Error('Tried to use StudioContext when none exists.')
}
return studioContext
}