Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropzone: Rejected and accepted files on the same callback function (Proposed fix) #3003

Closed
nicolassanmar opened this issue Nov 19, 2022 · 1 comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@nicolassanmar
Copy link
Contributor

nicolassanmar commented Nov 19, 2022

Context

Consider the following scenario, where a user uploads files to a dropzone and we want to keep track of the uploaded files:

const MyDropzoneComponent = () => {
  const [accepted, setAccepted] = useState([]);
  const [rejected, setRejected] = useState([]);
  
  return (
  <Dropzone onDrop={setAccepted} onReject={setRejected} accept={PDF_MIME_TYPE} />
  )
}

Problematic scenario

  1. User tries to upload a single '.png' file. It will get rejected, setting the rejected variable by onReject
  2. User uploads only '.pdf' files. This will only call onDrop since user did only upload valid files.

Problem

The final state of accepted and rejected do not reflect the last user drop

Solution

Add a new prop to the Dropzone called something like onDropAny that gets both accepted and rejected files. react-dropzone already provides this functionality so it should be easy to implement.
(it is called onDrop on the useDropzone hook)

This would make it possible to update the state of both accepted and rejected on the same function, guaranteeing to be able to set the state of the last user interaction

I am currently trying this on a fork!
This PR shows a way that this could be implemented:
#3010

@nicolassanmar nicolassanmar reopened this Nov 19, 2022
@nicolassanmar nicolassanmar changed the title Dropzone: Get both rejected and accepted files on the same callback function Dropzone: Rejected and accepted files on the same callback function (Proposed fix) Nov 19, 2022
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Nov 23, 2022
@rtivital
Copy link
Member

Added in 5.8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants