score:3

Accepted answer

the name of your prop is ondelete, so in your component todo.js, you have to call your function like below

<button onclick={() => this.props.ondelete(this.props.id)}>delete</button>

as answer to your comment

your state is define like

   this.state = {
      todos: [
        { id: 1, description: 'walk the cat', iscompleted: true },
        { id: 2, description: 'throw the dishes away', iscompleted: false },
        { id: 3, description: 'buy new dishes', iscompleted: false}
      ],
      newtododescription: ''
    };

so, your function deletetodo should be like

deletetodo(id) {
    this.setstate((prevstate) => ({
        todos: prevstate.todos.filter(item => item.id !== id),
    }))
};

score:0

i'll suggest you should use the splice method.


Related Query

More Query from same tag