import * as React from "react" ; interface ErrorContextType { readonly error ? : string ; readonly setError : ( error : string ) => void ; readonly clearError : ( ) => void ; } const defaultContext = { setError : ( ) => { return ; } , clearError : ( ) => { return ; } } ; const ErrorContext = React . createContext < ErrorContextType > ( defaultContext ) ; export const useError = ( ) : ErrorContextType => React . useContext ( ErrorContext ) ; export function ErrorProvider ( { children } ) { const [ error , setError ] = React . useState < string > ( ) ; const context = { error : error , setError : setError , clearError : ( ) => { setError ( undefined ) ; } } ; return < ErrorContext . Provider value = { context } > { children } < /ErrorContext.Provider>; }