I'm new working with ReactJS, I started a project a simple CRUD just for practice. So, I have a table and I want to add a class so that this element disappears when I press a button
The problem is when I press the button delete, React adds a class to all elements, disappearing all of them
How to delete only the parent element of a clicked button ? I tried to get the id of an event but I don't know how to specify to what element I want to add a class.
deleteTask(e, id){
//let trDelete =
e.currentTarget.parentNode.getAttribute('key');
M.toast({html: 'Task Deleted'})
const currState = this.state.active;
this.setState({active: !currState});
}
{
this.state.tasks.map(task => {
return (
<tr data-key={task._id} key={task._id} className={this.state.active ? "scale-transition scale-out": ""}>
<td>{task.title}</td>
<td>{task.description}</td>
<td>
<button className="btn light-blue darken-4" onClick={(e) => this.deleteTask(e, task._id)}>
<i className="material-icons">
delete
</i>
</button>
<button className="btn light-blue darken-4" style={{margin: '4px'}}>
<i className="material-icons">
edit
</i>
</button>
</td>
</tr>
)
})
}