import { useReducer, createContext } from 'react'; export interface InitialState { collapse?: boolean; } interface ContextValue extends InitialState { dispatch?: React.Dispatch; } export const initialState: InitialState = {}; export const Context = createContext({}); export const reducer = (state: InitialState, action: InitialState): InitialState => { return { ...state, ...action }; }; export const Provider: React.FC> = ({ children, value }) => { const [state, dispatch] = useReducer(reducer, { ...initialState, ...value }); return {children}; };