feat: update fetch opg function

This commit is contained in:
2024-03-13 10:24:45 +07:00
parent 1be84f3139
commit 3005d27403
3 changed files with 32 additions and 47 deletions

View File

@@ -0,0 +1,24 @@
import { useQuery } from "@tanstack/react-query";
import { invoke } from "@tauri-apps/api/core";
export function usePreview(url: string) {
const { isLoading, isError, data } = useQuery({
queryKey: ["url", url],
queryFn: async () => {
try {
const cmd = await invoke("fetch_opg", { url });
console.log(cmd);
return cmd;
} catch (e) {
throw new Error(e);
}
},
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
staleTime: Infinity,
retry: 2,
});
return { isLoading, isError, data };
}