Object is not extensible error when creating new attribute for array of objects
-
const tableData = this.state.uploadedFiles.map((file) => { const url = file.url; const filename = file.filename; console.log(url); file.action = this.deleteButton(file); file.downloadUrl = ( <a href="#" onClick={(e) => this.handleDownload(e, url, filename)}> {url} </a> ); return file; });
Have to create a new object
const tableData = this.state.uploadedFiles.map((file) => { const newFile = Object.assign({}, file); const url = file.url; const filename = file.filename; console.log(url); newFile.action = this.deleteButton(file); newFile.downloadUrl = ( <a href="#" onClick={(e) => this.handleDownload(e, url, filename)}> {url} </a> ); return newFile; });