I am learning React.js, trying to build a todoList app. So in my component, I am creating a <li>
element to display a to-do item that the user enters in the form. I also display a tiny delete button next to it. I basically want to delete this entry when the user clicks on the delete button. The function removeItem()
I created in my component is the event handler for the button click. But when I call the removeItem()
i keep getting an "typeEror, removeItem does not exist". I have tried moving it around, done binding of the this
keyword, used an arrow function to no avail. Here's what the code looks like:
var TodoItems = React.createClass({
removeItem: function() {
alert("We are removing an Item");////////////
},
render: function() {
var todoEntries = this.props.entries;
function createTasks(item) {
return <li key={item.key}>{item.text}<button onClick={() => this.removeItem()} className="deleteBtns">x</button></li>
}
var listItems = todoEntries.map(createTasks);
return (
<ul className="theList">
{listItems}
</ul>
);
}
});
What am I missing?