I am learning react and getting this error that onDelete is not defined but the tutorial which i am following is not getting the error. This is the Code also sharing a snipshot. Snip shot of Code Can anyone tell me why i am getting this error and how to resolve it
import React from 'react';
import TodoItem from './todoItem';
export default function Todos(props) {
return (
<div className="container">
<h3 className="my-3 text-center">Todo's List</h3>
{ props.todos.map((todo)=> {
return <TodoItem todo={todo} onDelete={onDelete}/>})
}
</div>
)
}
You cannot defined the props and don't tell them about the props so why this happened.
Updated this
import React from 'react';
import TodoItem from './todoItem';
export default function Todos(props) {
render(){ //Added
const { onDelete } = this.props; //Added
return (
<div className="container">
<h3 className="my-3 text-center">Todo's List</h3>
{ props.todos.map((todo)=> {
return <TodoItem todo={todo} onDelete={onDelete}/>})
}
</div>
)
}
}
This is code file to map list items.
https://github.com/mashaimtahir/React/blob/master/todo-app%20v2/src/Components/counters.jsx
This the link of complete todo app.
https://github.com/mashaimtahir/React/tree/master/todo-app%20v2/src