snort/src/Element/ProxyImg.tsx

18 lines
467 B
TypeScript
Raw Normal View History

2023-01-31 14:41:21 +00:00
import useImgProxy from "Feed/ImgProxy";
import { useEffect, useState } from "react";
2023-01-31 15:53:47 +00:00
export const ProxyImg = (props: any) => {
2023-01-31 16:07:46 +00:00
const { src, size, ...rest } = props;
2023-01-31 14:41:21 +00:00
const [url, setUrl] = useState<string>();
const { proxy } = useImgProxy();
useEffect(() => {
if (src) {
2023-01-31 16:07:46 +00:00
proxy(src, size)
2023-01-31 14:41:21 +00:00
.then(a => setUrl(a))
.catch(console.warn);
}
}, [src]);
return <img src={url} {...rest} />
}