I am creating a To-do app & I am not able to write the code for deleting the elements of the list when we click them. I want the specific item to delete when a user clicks on it
class Todo extends React.Component {
constructor(props) {
super(props);
this.state={todos:[]};
}
save() {
var todos = [...this.state.todos];
todos.push(this.newText.value);
this.setState({todos});
}
remove{
}
render(){
return(
<div className="list">
<h1> TO-DO List</h1>
<input type="text" ref={(ip) => {this.newText = ip}}/>
<button onClick={this.save.bind(this)} className="btn btn-primary glyphicon glyphicon-floppy-saved">Save
</button>
<ul>
{this.state.todos.map(function(todo) {
return <li>{todo}</li>
})}
</ul>
</div>
)
}
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…