Skip to content

Commit ac12903

Browse files
committed
fix(dropzone): BIC's behaviour to return Blob
Ada bug (mungkin) di browser-image-compression yg seharusnya return File malah return Blob, ada issue yang nge fix tp blom di pr di repo nya See Donaldcwl/browser-image-compression#203
1 parent 7f92b8b commit ac12903

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

components/DropZone.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useState, useEffect } from "react";
2-
import { Box, Text, Image, Center } from "@chakra-ui/react";
2+
import { Box, Text, Image, Center, Progress } from "@chakra-ui/react";
33
import { useController } from "react-hook-form";
44
import { useDropzone } from "react-dropzone";
55
import imageCompression from "browser-image-compression";
66
import Swal from "sweetalert2";
7+
import axios from "axios";
78

89
const DropZone = ({
910
control,
@@ -20,15 +21,17 @@ const DropZone = ({
2021
const {
2122
field: { value, onChange },
2223
fieldState: { error },
23-
} = useController({ control, name, rules, defaultValue });
24-
25-
useEffect(() => {
26-
return () => {
27-
if (value && value.preview) {
28-
URL.revokeObjectURL(value.preview);
29-
}
30-
};
31-
}, [value]);
24+
} = useController({
25+
control,
26+
name,
27+
rules,
28+
defaultValue: defaultValue
29+
? axios
30+
.get(defaultValue)
31+
.then((resp) => resp.data)
32+
.catch((err) => defaultValue)
33+
: undefined,
34+
});
3235

3336
const { getRootProps, getInputProps } = useDropzone({
3437
maxFiles: 1,
@@ -40,7 +43,14 @@ const DropZone = ({
4043
maxWidthOrHeight: 512,
4144
useWebWorker: true,
4245
})
43-
.then((file) => onChange(file))
46+
.then((file) =>
47+
onChange(
48+
new File([file], file.name, {
49+
lastModified: file.lastModified,
50+
type: file.type,
51+
})
52+
)
53+
)
4454
.catch((err) => {
4555
console.error(err);
4656
Swal.fire(

0 commit comments

Comments
 (0)