Refactor FileUpload component to ensure onChange is called consistently after file selection, improving state management for file uploads.
This commit is contained in:
parent
775393dfd1
commit
b5dd009d1a
@ -54,6 +54,7 @@ const FileUpload = ({
|
||||
currentFiles.length === 0
|
||||
: !currentFiles
|
||||
setHasNoItems(noItems)
|
||||
onChange(currentFiles)
|
||||
}, [currentFiles, multiple])
|
||||
|
||||
const handleFileUpload = async (file) => {
|
||||
@ -68,11 +69,9 @@ const FileUpload = ({
|
||||
// For multiple files, add to existing array
|
||||
const newFiles = [...currentFiles, uploadedFile]
|
||||
setCurrentFiles(newFiles)
|
||||
onChange(newFiles)
|
||||
} else {
|
||||
// For single file, replace the value
|
||||
setCurrentFiles(uploadedFile)
|
||||
onChange(uploadedFile)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@ -88,11 +87,9 @@ const FileUpload = ({
|
||||
// For multiple files, add to existing array
|
||||
const newFiles = [...currentFiles, selectedFile]
|
||||
setCurrentFiles(newFiles)
|
||||
onChange(newFiles)
|
||||
} else {
|
||||
// For single file, replace the value
|
||||
setCurrentFiles(selectedFile)
|
||||
onChange(selectedFile)
|
||||
}
|
||||
// Clear the selection
|
||||
setSelectedFile(null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user