I have the below function that adds attachments from an <input type="file" multiple />
to a parent's state.
That works fine until the user wants to add another attachment/s, the new attachment/s override the existing ones, how can I have the new attachments be added to the existing attachments array?
handleAddAttachments = fileList => {
this.props.handleChange('attachments', Array.from(fileList));
};
I tried that but it doesn't seem to work.
handleAddAttachments = fileList => {
const { attachments } = this.props.ticket;
this.props.handleChange('attachments', [...attachments, fileList]);
};
The parent handleChange
function:
makeHandleChange = (pageName, change) => {
this.setState({
ticket: { ...this.state.ticket, [pageName]: change },
});
};