So erhalten Sie React component state in dieser Komponentenfunktion. Dies hat keine Objekte mit Status verknüpft. Ich bekomme diesen.Status undefined in Board removeComment
Funktion. Grundsätzlich in Board removeComment
Funktion möchte ich Kommentare Element auf diesem Index (als Argument übergeben).Zugriff auf `this.state` innerhalb der Event-Handler-Funktion nicht möglich: ReactJS
class Board extends React.Component {
constructor(props) {
super(props);
this.state = {
comments:[
"One",
"Two",
"Three",
"four",
"five"
]};
};
removeComment(index) {
console.log('i was called',this.state);
}
render() {
console.log(this.state);
return (
<div className="board">
{
this.state.comments.map((text,i) => {
return (
<Comment key ={i} index = {i} commentText={text} removeComment={this.removeComment}/>
)
})
}
</div>
);
}
}
class Comment extends React.Component {
removeComment() {
var index = this.props.index;
this.props.removeComment(index);
}
render() {
return(
<div onClick={this.removeComment.bind(this)}>{this.props.commentText}</div>
);
}
}
Dank Geck. Du hast meinen Tag gerettet. –
froh, dir zu helfen :) –