From a314b5350e269676e8c39eda4cc7842751b1a7fc Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Tue, 1 Sep 2020 02:32:06 +0800
Subject: ...

---
 .../ClientApp/src/app/views/common/BlobImage.tsx   | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 Timeline/ClientApp/src/app/views/common/BlobImage.tsx

(limited to 'Timeline/ClientApp/src/app/views/common/BlobImage.tsx')

diff --git a/Timeline/ClientApp/src/app/views/common/BlobImage.tsx b/Timeline/ClientApp/src/app/views/common/BlobImage.tsx
new file mode 100644
index 00000000..0dd25c52
--- /dev/null
+++ b/Timeline/ClientApp/src/app/views/common/BlobImage.tsx
@@ -0,0 +1,27 @@
+import React from "react";
+
+const BlobImage: React.FC<
+  Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src"> & {
+    blob?: Blob | unknown;
+  }
+> = (props) => {
+  const { blob, ...otherProps } = props;
+
+  const [url, setUrl] = React.useState<string | undefined>(undefined);
+
+  React.useEffect(() => {
+    if (blob instanceof Blob) {
+      const url = URL.createObjectURL(blob);
+      setUrl(url);
+      return () => {
+        URL.revokeObjectURL(url);
+      };
+    } else {
+      setUrl(undefined);
+    }
+  }, [blob]);
+
+  return <img {...otherProps} src={url} />;
+};
+
+export default BlobImage;
-- 
cgit v1.2.3

