Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 62x 398x 15x 398x 15x | import { useQuery } from "react-query";
import { isTestEnvironment } from "@constants/constants";
const useFetchImage = (baseImageUrl: string) => {
const fetchImage = async (url: string): Promise<string> => {
Eif (isTestEnvironment) return url;
if (!url) return "";
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(url);
img.onerror = () => reject(new Error("Failed to load image"));
img.src = url;
});
};
return useQuery(
["media-library-image", baseImageUrl],
() => fetchImage(baseImageUrl),
{
enabled: !!baseImageUrl,
retry: 8,
retryDelay: () => 3000,
},
);
};
export default useFetchImage;
|