snort/src/Element/ProxyImg.tsx

19 lines
430 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) => {
const { src, size, ...rest } = props;
const [url, setUrl] = useState<string>();
const { proxy } = useImgProxy();
2023-01-31 14:41:21 +00:00
useEffect(() => {
if (src) {
proxy(src, size)
.then((a) => setUrl(a))
.catch(console.warn);
}
}, [src]);
2023-01-31 14:41:21 +00:00
return <img src={url} {...rest} />;
};