import React , { createContext , useContext } from 'react' ; import { Observable } from 'rxjs' ; import { CoreStart , ScopedHistory , CoreTheme } from '../../../../../src/core/public' ; import { LicensingPluginSetup , ILicense } from '../../../licensing/public' ; import { TelemetryPluginStart } from '../../../../../src/plugins/telemetry/public' ; import { ClientConfigType } from '../types' ; import { BreadcrumbService } from './breadcrumbs' ; const AppContext = createContext < AppDependencies | undefined > ( undefined ) ; export interface AppDependencies { core : CoreStart ; services : { breadcrumbService : BreadcrumbService ; history : ScopedHistory ; } ; plugins : { licensing : LicensingPluginSetup ; telemetry ? : TelemetryPluginStart ; } ; docLinks : { security : string ; } ; store : { initialLicense : ILicense ; } ; config : ClientConfigType ; theme$ : Observable < CoreTheme > ; } export const AppContextProvider = ( { children , value , } ) => { return < AppContext . Provider value = { value } > { children } < /AppContext.Provider>; } ; export const AppContextConsumer = AppContext . Consumer ; export const useAppContext = ( ) => { const ctx = useContext ( AppContext ) ; if ( ! ctx ) { throw new Error ( '"useAppContext" can only be called inside of AppContext.Provider!' ) ; } return ctx ; } ;