import { createContext, Dispatch, FC, SetStateAction, useContext, useMemo, useState, } from 'react' export type View = 'cur_file' | 'overview' export const ReviewPanelViewContext = createContext('cur_file') type ViewActions = { setView: Dispatch> } const ReviewPanelViewActionsContext = createContext( undefined ) export const ReviewPanelViewProvider: FC = ({ children }) => { const [view, setView] = useState('cur_file') const actions = useMemo( () => ({ setView, }), [setView] ) return ( {children} ) } export const useReviewPanelViewContext = () => { return useContext(ReviewPanelViewContext) } export const useReviewPanelViewActionsContext = () => { const context = useContext(ReviewPanelViewActionsContext) if (!context) { throw new Error( 'useViewActionsContext is only available inside ViewProvider' ) } return context }