Open NicoPowers opened 6 months ago
Hi Nicolas,
Note that the detail.value
taken by onChange
contains the new value with all files to be uploaded, not only the newly added or removed file(s). So I believe you would only need to run your type checks again against he new value, but after that you can just assign the field value to the new value without having to compare both arrays.
This part is unnecessary:
// remove any files that already exist in the field
if (field.value) {
field.value.forEach((file: File) => {
filesToUpload = filesToUpload.filter((f) => f !== file);
});
}
Let me know if this helps.
Description
Hello,
When we add or remove files from the file upload component, the event that is passed in to the
onChange
prop is as follows:However, when uploading or remove files (by hitting on the X on one of the files), the event cannot tell them apart, therefore when trying to implement logic to prevent the use from uploading duplicated files, it is impossible to know whether they are uploading or removing.
This is how I am trying to add logic to the file upload, using
react-hook-form
Code of Conduct