Skip to content

How to reset a dropzone to have no files? #1160

Answered by danielnoravia
ndp asked this question in Q&A
Discussion options

You must be logged in to vote

Simply stop using acceptedFiles 🙂

Create your own file array with useState:

const [files, setFiles] = useState<File[]>([]);

Then write your onDrop callback (which gives you the File[] as the first agument) in such way that it will copy the files to your state:

onDrop: (newFiles: File[]) => {
  setFiles([ ...files, ...newFiles ]);
}

Of course you are encouraged to write your other callbacks as well (e.g., onFileDialogCancel: () => setFiles([]), etc) to handle your use case accordingly.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rolandjitsu
Comment options

Answer selected by rolandjitsu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants