Easy
A junior developer is building a todo list application and can't figure out why their delete functionality isn't working. What's the issue with the delete functionality, and how should it be fixed?
1class TodoList extends React.Component {2 constructor(props) {3 super(props);4 this.state = {5 todos: ['Learn React', 'Build Projects', 'Write Documentation']6 };7 }89 deleteTodo(index) {10 const newTodos = this.state.todos.filter((_, i) => i !== index);11 this.setState({ todos: newTodos });12 }1314 render() {15 return (16 <div>17 {this.state.todos.map((todo, index) => (18 <div key={index}>19 {todo}20 <button onClick={this.deleteTodo(index)}>Delete</button>21 </div>22 ))}23 </div>24 );25 }26}