import { ErrorToastOptions , Toast } from 'kibana/public' ; import { useState } from 'react' ; import { useKibana } from '../../common/lib/kibana' ; export const useErrorToast = ( ) => { const [ errorToast , setErrorToast ] = useState < Toast > ( ) ; const { notifications : { toasts } , } = useKibana ( ) . services ; return ( error ? , opts ? ) => { if ( errorToast ) { toasts . remove ( errorToast ) ; } if ( error ) { setErrorToast ( toasts . addError ( error , opts ) ) ; } } ; } ;