import { useToast } from "@chakra-ui/react"; import { DependencyList, useCallback } from "react"; export default function useAsyncErrorHandler(fn: () => Promise, deps: DependencyList = []): () => Promise { const toast = useToast(); return useCallback(async () => { try { return await fn(); } catch (e) { if (e instanceof Error) toast({ description: e.message, status: "error" }); } }, deps); }