Jaaneek / useFilePicker

Simple react hook to open browser file selector.

Home Page:https://use-file-picker.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deleting files from picker cause error

wozhendeaa opened this issue · comments

I like the file picker, it's easy to use and intuitive.
One small thing is that it doesn't seem to support edit and multiple upload tries.

so I delete a file from filesContent and it breaks the page when I re open the uploader (can't remove child). I'm guessing it's happening because the code tries to clear all files in the filecontent and can't find the ones I deleted.
Also I'd like to keep all the files in files content when users re open the uploader, it doesn't support that. I can save the current ones, but again, it will cause some bugs for the uploader.

I can work around this by maintaining my own seperate dataset, but it'll be nice if it does that out of the box

Hi @wozhendeaa!
Currently, use-file-picker does not support modifying the selected files directly.
When it comes to keeping the previous selection, we had a request for this feature some time ago. You can read the thread here: #51
Since we've got a similar feature request multiple times, we'll discuss that within the maintainers team and get back to you as quickly as possible.

so I delete a file from filesContent and it breaks the page when I re open the uploader (can't remove child). I'm guessing it's happening because the code tries to clear all files in the filecontent and can't find the ones I deleted.

How are you deleting those files? You are most probably mutating state data which is forbidden in react, the error is the expected outcome.

We will not allow modifying files in the state, as our vision of this hook is to make it declarative. Complying with the rest of the React ecosystem (tanstackquery, apollo etc...).

@MrKampla Out of his good heart is implementing a wrapper for useFilePicker called useImperativeFilePicker which will enable the desired behaviors. It's important to note for you and many other users of this package that the current behavior is the correct one, and any errors that you are getting are strictly because you are using react incorrectly, and you can implement any feature you wish using our hook as long as you follow react principles. Here is an example of similar issue raised on tanstack query package TanStack/query#530 (reply in thread)

tl;dr this functionality will be implemented by @MrKampla in form of a wrapper useImperativeFilePicker, what you are trying to do is very much likely to be antipattern in react and this is why you are getting errors

@wozhendeaa PR #68 with useImperativeFilePicker has been merged. I've published the new version of the package, so you should be able to use it in our latest release: 1.7.0. You can check out the new README section in order to see how to use it: Imperative picker
We're looking forward to hearing from you with some feedback.

Since no feedback was provided I'm closing this issue, everything was implemented by @MrKampla . Huge kudos to him