snort/src/Element/ProxyImg.tsx

17 lines
443 B
TypeScript
Raw Normal View History

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