import {createContext, FC, ReactNode, useContext} from "react";

type ApiState = {
    onLogout: () => void;
};
const apiContext = createContext<ApiState | undefined>(undefined);

export const useApiContext = () => {
    const context = useContext(apiContext);
    if (!context) throw new Error('useApiContext must be used within ApiContextProvider');
    return context;
}

type ApiContextProviderProps = {
    children: ReactNode;
    state: ApiState;
}
export const ApiContextProvider: FC<ApiContextProviderProps> = ({children, state}) => {

    return (
        <ApiContextProvider state={state}>
            {children}
        </ApiContextProvider>
    )
}
