aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/components/BlobImage.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-08-28 01:41:41 +0800
committercrupest <crupest@outlook.com>2023-08-28 01:41:41 +0800
commitb66a57071316434356e77e294ec22181e4db54d5 (patch)
tree2c000b459165834562cf420990e683e78fadae6c /FrontEnd/src/components/BlobImage.tsx
parent256cc9592a3f31fc392e1ccdb699aa206b7b47ce (diff)
downloadtimeline-b66a57071316434356e77e294ec22181e4db54d5.tar.gz
timeline-b66a57071316434356e77e294ec22181e4db54d5.tar.bz2
timeline-b66a57071316434356e77e294ec22181e4db54d5.zip
...
Diffstat (limited to 'FrontEnd/src/components/BlobImage.tsx')
-rw-r--r--FrontEnd/src/components/BlobImage.tsx15
1 files changed, 12 insertions, 3 deletions
diff --git a/FrontEnd/src/components/BlobImage.tsx b/FrontEnd/src/components/BlobImage.tsx
index 259c2210..cccf2f74 100644
--- a/FrontEnd/src/components/BlobImage.tsx
+++ b/FrontEnd/src/components/BlobImage.tsx
@@ -1,12 +1,13 @@
-import { ComponentPropsWithoutRef, useState, useEffect } from "react";
+import { ComponentPropsWithoutRef, useState, useEffect, useMemo } from "react";
type BlobImageProps = Omit<ComponentPropsWithoutRef<"img">, "src"> & {
imgRef?: React.Ref<HTMLImageElement>;
src?: Blob | string | null;
+ keyBySrc?: boolean;
};
export default function BlobImage(props: BlobImageProps) {
- const { imgRef, src, ...otherProps } = props;
+ const { imgRef, src, keyBySrc, ...otherProps } = props;
const [url, setUrl] = useState<string | null | undefined>(undefined);
@@ -22,5 +23,13 @@ export default function BlobImage(props: BlobImageProps) {
}
}, [src]);
- return <img ref={imgRef} {...otherProps} src={url ?? undefined} />;
+ const key = useMemo(() => {
+ if (keyBySrc) {
+ return url == null ? undefined : btoa(url);
+ } else {
+ return undefined;
+ }
+ }, [url, keyBySrc]);
+
+ return <img key={key} ref={imgRef} {...otherProps} src={url ?? undefined} />;
}