import React , { createContext , ReactChild , useContext , useState } from 'react' ; import { PolicyFromES } from '../../../../common/types' ; interface ListAction { actionType : 'viewIndexTemplates' | 'addIndexTemplate' | 'deletePolicy' ; selectedPolicy : PolicyFromES ; } export interface PolicyListContextValue { listAction : ListAction | null ; setListAction : ( policyAction : ListAction | null ) => void ; } const PolicyListContext = createContext < PolicyListContextValue > ( { listAction : null , setListAction : ( ) => { } , } ) ; export const PolicyListContextProvider = ( { children } ) => { const [ listAction , setListAction ] = useState < ListAction | null > ( null ) ; return ( < PolicyListContext . Provider value = { { listAction , setListAction , } } > { children } < /PolicyListContext.Provider>); } ; export const usePolicyListContext = ( ) : PolicyListContextValue => { const ctx = useContext ( PolicyListContext ) ; if ( ! ctx ) { throw new Error ( 'usePolicyListContext can only be called inside of PolicyListContext!' ) ; } return ctx ; } ;