import { useEffect } from "react" ; import { useDialogManager } from "../mui/dialogs/MUIDialogControllers" ; import { AsyncOptions , useAsync } from 'react-async' ; import { NULL_FUNCTION } from "polar-shared/src/util/Functions" ; export function useComponentDidMount ( delegate ) { useEffect ( ( ) => delegate ( ) , [ ] ) ; } export function useComponentWillUnmount ( delegate ) { useEffect ( ( ) => delegate , [ ] ) ; } export function useAsyncWithError < T > ( opts ) { const dialogs = useDialogManager ( ) ; const { data , error } = useAsync ( opts ) ; if ( error ) { dialogs . confirm ( { title : "An error occurred." , subtitle : "We encountered an error: " + error . message , type : 'error' , onAccept : NULL_FUNCTION , } ) ; } return data ; }