import type { HttpSetup } from 'src/core/public' ; import type { FunctionComponent } from 'react' ; import React , { createContext , useContext } from 'react' ; import { useKibana } from '../../shared_imports' ; import type { ReportingAPIClient } from './reporting_api_client' ; interface ContextValue { http : HttpSetup ; apiClient : ReportingAPIClient ; } const InternalApiClientContext = createContext < undefined | ContextValue > ( undefined ) ; export const InternalApiClientProvider = ( { apiClient , children } ) => { const { services : { http } , } = useKibana ( ) ; return ( < InternalApiClientContext . Provider value = { { http , apiClient } } > { children } < /InternalApiClientContext.Provider>); } ; export const useInternalApiClient = ( ) : ContextValue => { const ctx = useContext ( InternalApiClientContext ) ; if ( ! ctx ) { throw new Error ( '"useInternalApiClient" can only be used inside of "InternalApiClientContext"' ) ; } return ctx ; } ;