My Objective is to delete a particular file from the file list but when I want to delete the last file is being deleted instead of the required file.
Here is the code:
 {this.state.myFiles.map(file => (
        <p key={file.name}>
          {file.name} ({file.size} bytes)
          <button
            className={"material-icons delete"}
            onClick={() => this.handleRemoveFile(file.name)}
          >
            Remove file
          </button>
        </p>))}
Removing particular file from the files list:
handleRemoveFile = (fileName) => {
const myFiles = [...this.state.myFiles];
 myFiles.splice(myFiles.indexOf(fileName), 1)
        this.setState({ myFiles })
}
I couldn't able to delete a particular file, it is deleting the last one from the file list, can anyone help me in removing the particular file from the file list?
Thanks! in advance.
 
     
    