I'm getting the error when using this function:
private _addFile = (event) => {
//let resultFile = document.getElementById('file');
let resultFile = event.target.files;
console.log(resultFile);
let fileInfos = [];
for (var i = 0; i < resultFile.length; i++) {
var fileName = resultFile[i].name;
console.log(fileName + 'fileName');
var file = resultFile[i];
var reader = new FileReader();
reader.onload = ((file) => {
return (e) => {
//Push the converted file into array
fileInfos.push({
"name": file.name,
"content": e.target.result
});
};
})(file);
reader.readAsArrayBuffer(file);
}
this.setState({
fileInfos,
fileArray: resultFile,
}, () => {
console.log(this.state.fileArray);
});
}
and this JSX:
{this.state.fileArray ? this.state.fileArray.map((item, i) => <li key={i}>{item}</li>) : null }
I'm still a learner to ReactJS so explanations are always helpful. I've read a few similar posts, and have tried to follow but they also cause the same error.