import React , { useContext , createContext , useCallback } from 'react' ; import { HttpSetup , ToastsSetup } from 'kibana/public' ; import { LicenseStatus } from '../../../common' ; export interface ContextArgs { http : HttpSetup ; notifications : ToastsSetup ; initialLicenseStatus : LicenseStatus ; } export interface ContextValue { http : HttpSetup ; notifications : ToastsSetup ; getLicenseStatus : ( ) => LicenseStatus ; } const AppContext = createContext < ContextValue > ( null as any ) ; export const AppContextProvider = ( { children , args : { http , notifications , initialLicenseStatus } , } ) => { const getLicenseStatus = useCallback ( ( ) => initialLicenseStatus , [ initialLicenseStatus ] ) ; return ( < AppContext . Provider value = { { http , notifications , getLicenseStatus , } } > { children } < /AppContext.Provider>); } ; export const useAppContext = ( ) => { const ctx = useContext ( AppContext ) ; if ( ctx == null ) { throw new Error ( `useAppContext must be called inside AppContextProvider` ) ; } return ctx ; } ;