event UPLOADER_EVENTS.ITEM_FINISH gets fired only once when uploading multiple files
max-l opened this issue · 3 comments
I want to use the UPLOADER_EVENTS.ITEM_FINISH event to dispatch a change of state, to update a view of uploaded files,
The relevant code looks like this :
const listeners = useMemo(() => ({
[UPLOADER_EVENTS.ITEM_FINISH]: (item) => {
fileManagerDispatcher({name: 'newFile', fileName: item.file.name})
},
}), [])
<Uploady
listeners={listeners}
destination={{ url: `${url}${path}` }}
grouped={false}
debug={false}
inputFieldName={"files"}
>
<UploadButtonDiv/>
</Uploady>
It works when I upload a single file.
If I upload multiple files, the event only gets fired for the first file that is uploaded.
Is this a bug ?
I tried to use useItemFinishListener to register a callback on "item finished" event :
const Uplog = ({onFileAddedEvent}) => {
useItemFinishListener(item => {
console.log(item)
})
const UploadButton = ({url, path, onFileAddedEvent}) =>
<Uploady
destination={{ url: `${url}${path}` }}
grouped={false}
debug={false}
inputFieldName={"files"}
>
<UploadButtonDiv/>
<Uplog onFileAddedEvent={onFileAddedEvent}/>
</Uploady>
}
Same thing happens: the callback gets fired only once when I upload multiple files
Hey @max-l
Its unlikely there's an issue with the finish listener under most conditions as its working properly in many applications.
I took your code and gave it a try here. You can upload several items and their Finish event will be logged as expected.
Can you create a reproducing example that I can check?
In addition, I recommend checking whether your event handler is doing a state change that is causing a re-render of the Uploady component with un-memoized props. This can cause such issues I believe.
closing for now. without repro cant proceed