I am trying to upload files using React Hooks and the Upload component from AntDesign. I thought it would be no problem, and I have been trying many different ways to do this using React Hooks (without Hooks, I can do it without any issue at all).
I made a simplified example here: https://codesandbox.io/embed/upload-with-react-hooks-ant-design-1jmod?fontsize=14&hidenavigation=1&theme=dark
I am sure I am doing it wrong, but it seems I am not able to find the best way to achieve this. I am always running into stale closures and I am not sure how to avoid this.
What's the problem? I don't get the file in the processRemainingFiles. Have a look in the console, after dropping a file in it. You'll get:
[uploadFile] undefined
Even though the logic seems to work here for me, I know there is another issue with this code: if another files is dropped, then it would start uploading instantly as well. There are many ways to go around this, but since it makes the code longer, I preferred to share something simpler.