Hey I am trying to delete the element I have clicked on
My app.js
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
ninja: [
{
name: 'Ryu',
age: 30,
belt: 'black',
id: 1
}, {
name: 'Jacy',
age: 34,
belt: 'yellow',
id: 2
}, {
name: 'Ikenna',
age: 20,
belt: 'green',
id: 3
}, {
name: 'Cole',
age: 50,
belt: 'red',
id: 4
}
]
}
}
deleteNinja (itemToBeDeleted) {
console.log(itemToBeDeleted)
}
render = () => <div>
{this
.state
.ninja
.map(function (ninja) {
return (
<div>
<div>{ninja.name}</div>
<div>{ninja.age}</div>
<div>{ninja.belt}</div>
<button
onClick={this
.state
.deleteNinja
.bind(this)}>Delete</button>
</div>
)
})}
</div>
}
When I add the function deleteninja to my button it tells me cannot read state of undefined. I read something about binding it and still it wont do it. If I remove the button everything works fine