import React , { useContext , createContext , FC } from 'react' ; import type { MyForwardableState } from './types' ; interface ContextValue { forwardedState ? : MyForwardableState ; } const ApplicationContext = createContext < undefined | ContextValue > ( undefined ) ; export const ApplicationContextProvider = ( { forwardedState , children , } ) => { return ( < ApplicationContext . Provider value = { { forwardedState } } > { children } < /ApplicationContext.Provider>); } ; export const useApplicationContext = ( ) : ContextValue => { const ctx = useContext ( ApplicationContext ) ; if ( ! ctx ) { throw new Error ( 'useApplicationContext called outside of ApplicationContext!' ) ; } return ctx ; } ;