init
This commit is contained in:
30
src/components/Hooks/useFetchImageUrl.ts
Normal file
30
src/components/Hooks/useFetchImageUrl.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user