I have bound the removeNote function in the constructor, but I still get the cannot read property error.
class Wall extends React.Component {
constructor(props) {
super(props);
this.state = {
noteDataArray: ['Note value 1 yay','2 notes']
};
this.removeNote = this.removeNote.bind(this);
}
saveNote(value, index) {
var temp = this.state.noteDataArray;
temp[index] = value;
this.setState({noteDataArray: temp});
}
removeNote(index) {
var temp = this.state.noteDataArray;
temp.splice(index, 1);
this.setState({noteDataArray: temp});
}
render() {
return (
<div className="Wall">
{this.state.noteDataArray.map(function (value, index) {
return (
<Notes key={index} index={index} removeit={this.removeNote} >
{value}
</Notes>
);
})}
</div>
)
}
}
When I use the same binding method in another component , it works.