timeline-frontend/src/components/Hooks/useFetchImageUrl.ts

31 lines
728 B
TypeScript
Raw Normal View History

2025-07-22 14:52:55 +00:00
import { fetchImage } from '@/pages/list/basic-list/service';
import { useRequest } from '@umijs/max';
import { useEffect, useState } from 'react';
const useFetchImageUrl = (imageInstanceId: string) => {
const [imageUrl, setImageUrl] = useState("error");
const { data: response, run } = useRequest(
() => {
return fetchImage(imageInstanceId);
},
{
manual: true,
onSuccess: (data) => {
console.log(data);
},
},
);
useEffect(() => {
if (response) {
setImageUrl(URL.createObjectURL(response));
}
}, [response]);
useEffect(() => {
if (imageInstanceId) {
run();
}
}, [imageInstanceId]);
return imageUrl;
};
export default useFetchImageUrl;