import React , { createContext , ReactChild , useContext } from 'react' ; import { PolicyFromES , SerializedPolicy } from '../../../../common/types' ; export interface EditPolicyContextValue { isNewPolicy : boolean ; policy : SerializedPolicy ; existingPolicies : PolicyFromES [ ] ; license : { canUseSearchableSnapshot : ( ) => boolean ; } ; policyName ? : string ; indices : string [ ] ; indexTemplates : string [ ] ; } const EditPolicyContext = createContext < EditPolicyContextValue > ( null as any ) ; export const EditPolicyContextProvider = ( { value , children , } ) => { return < EditPolicyContext . Provider value = { value } > { children } < /EditPolicyContext.Provider>; } ; export const useEditPolicyContext = ( ) : EditPolicyContextValue => { const ctx = useContext ( EditPolicyContext ) ; if ( ! ctx ) { throw new Error ( 'useEditPolicyContext can only be called inside of EditPolicyContext!' ) ; } return ctx ; } ;