Ukuran file gambar dalam react-dropzone
import React, { useState } from "react";
import { useDropzone } from "react-dropzone";
const UploadFile = () => {
const [errors, setErrors] = useState("");
const { getRootProps, getInputProps } = useDropzone({
multiple: false,
onDrop: (acceptedFiles, fileRejections) => {
fileRejections.forEach((file) => {
file.errors.forEach((err) => {
if (err.code === "file-too-large") {
setErrors(`Error: ${err.message}`);
}
if (err.code === "file-invalid-type") {
setErrors(`Error: ${err.message}`);
}
});
});
}
return (
<div{...getRootProps()}>
<input {...getInputProps()} title={title} />
<p style={{ color: "red", padding: 5, margin: 0, fontSize: 14 }}>
{errors}
</p>
</div>
);
};
Inquisitive Ibex