mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-10-11 05:13:21 +02:00
Finish basic list views
This commit is contained in:
14
src/hooks/use-async-error-handler.ts
Normal file
14
src/hooks/use-async-error-handler.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useToast } from "@chakra-ui/react";
|
||||
import { DependencyList, useCallback } from "react";
|
||||
|
||||
export default function useAsyncErrorHandler<T = any>(fn: () => Promise<T>, deps: DependencyList = []): () => Promise<T | undefined> {
|
||||
const toast = useToast();
|
||||
|
||||
return useCallback(async () => {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (e) {
|
||||
if (e instanceof Error) toast({ description: e.message, status: "error" });
|
||||
}
|
||||
}, deps);
|
||||
}
|
Reference in New Issue
Block a user