material-ui-dropzone
material-ui-dropzone copied to clipboard
onChange event fire on component mount
Bug Report
Describe the bug
I'm trying to fire some functions on the onChange event, which from what I understand from the document only fire when files change but somehow it also fires when component mount. Is there something I'm missing here?
Steps to reproduce
Steps to reproduce the behavior:
- Go to 'https://codesandbox.io/s/focused-bogdan-nqnxb?file=/src/App.js'
- See console.log
Expected behavior
Codes inside the onChange event should not run when component mount or when initial files are provided.
Versions
@material-ui/coreversion: [e.g. 4.11]material-ui-dropzoneversion: [e.g. 3.3.1]
Is there any update on this? I'm experiencing the same annoying issue. If someone knows at least a workaround, that would be really appreciated.
Same issue.. any solution or workaround
Bumping this +1
For those still following this, I commented on the PR. IMO this isn't actually an issue - especially since if we provide initialFiles to the DropzoneArea, there's some processing that the DropzoneArea performs before that initial onChange call. (Although I can see the argument that it shouldn't fire if initialFiles is empty.)
Does anyone have an example where this is actually an issue in their code? If you're performing operations besides setting state in your onChange callback, I would expect it to be operations that can handle an empty array being passed in, as well as the same array being passed in across subsequent calls.
@tier42-mike let say that I try to load some files from the backend, and then send the last dropped file to the backend via onChange. It wouldn't make sense to fire the onChange right away when the intialFiles props is provided.
@tier42-mike If there is an initial state that would only change on a file change, we would need to do something to track the first onchange call so the component doesn't change from the initial state. It's easy to add a handler for an empty array, however removing all files , i.e. from 1 file to 0 files, would cause an onChange event with an empty array that would be indistinguishable from the onload change.
I also am not sure if there is any scenario where the onChange doesn't run on initial render. I have no idea, so I would have to blind faith write my code to assume there is on initial onChange for what should be an onLoad action. This is my primary concern with this library, everything else appears excellent.