Mounted check on StorageUploadField.tsx

This commit is contained in:
francesco
2021-11-15 18:22:38 +01:00
parent 24245d7843
commit f0da316868

View File

@@ -648,10 +648,15 @@ export function StorageUploadProgress({
const [error, setError] = React.useState<string>();
const [loading, setLoading] = React.useState<boolean>(false);
const mounted = React.useRef(false);
useEffect(() => {
mounted.current = true;
if (entry.file)
upload(entry.file, entry.fileName);
return () => {
mounted.current = false;
};
}, []);
function upload(file: File, fileName?: string) {
@@ -663,12 +668,15 @@ export function StorageUploadProgress({
.then(async ({ path }) => {
console.debug("Upload successful");
await onFileUploadComplete(path, entry, metadata);
setLoading(false);
if (mounted.current)
setLoading(false);
})
.catch((e) => {
console.error("Upload error", e);
setError(e.message);
setLoading(false);
if (mounted.current) {
setError(e.message);
setLoading(false);
}
snackbarContext.open({
type: "error",
title: "Error uploading file",