const [Collect, setCollect] = React.useState({
visible: false,
files:[],
uploading: 0,
team:"",
manager:"",
owner:"",
fileNames: [],
status:""
});
function fileOnChange(e){
// here update files and filenames arrays
}
我有一个功能组件,该组件的对象带有上述数组。每当从输入中选择新文件时,如何更新数组? fileOnChange方法来更新添加文件和文件名
答案 0 :(得分:0)
您可以创建另一个变量来存储以前的文件名和文件
let temp1 = Collect.filenames;
let temp2 = Collect.files;
temp1.push('anotherFilename');
temp2.push('anotherFile');
setCollect({...Collect, filenames: temp1, files: temp2});