diff options
author | crupest <crupest@outlook.com> | 2020-08-24 22:59:45 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-24 22:59:45 +0800 |
commit | de1d582bf2ed7062fd400459f30d463d47ef9982 (patch) | |
tree | 777e27f954c9fd7beab36aad61bb767a28d65a89 /Timeline/ClientApp/src/app/common/BlobImage.tsx | |
parent | 5a8fb35c2791a921d8833beb37aa2edd5047da4c (diff) | |
download | timeline-de1d582bf2ed7062fd400459f30d463d47ef9982.tar.gz timeline-de1d582bf2ed7062fd400459f30d463d47ef9982.tar.bz2 timeline-de1d582bf2ed7062fd400459f30d463d47ef9982.zip |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/common/BlobImage.tsx')
-rw-r--r-- | Timeline/ClientApp/src/app/common/BlobImage.tsx | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/Timeline/ClientApp/src/app/common/BlobImage.tsx b/Timeline/ClientApp/src/app/common/BlobImage.tsx index 7e5e2447..8602f550 100644 --- a/Timeline/ClientApp/src/app/common/BlobImage.tsx +++ b/Timeline/ClientApp/src/app/common/BlobImage.tsx @@ -1,29 +1,29 @@ -import React from 'react';
-
-import { ExcludeKey } from '../utilities/type';
-
-const BlobImage: React.FC<
- ExcludeKey<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;
+import React from "react"; + +import { ExcludeKey } from "../utilities/type"; + +const BlobImage: React.FC< + ExcludeKey<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; |