添加删除按钮错误TypeError: Cannot read property 'props' of undefined
在commentList.js中:
<ul className="list-group mb-3"> {comments.map((comment,index)=> <li key={index} className="list-group-item">{comment} <button onClick={ (e)=> this.props.onDeleteComment(e)}>X</button> </li> )} </ul>
APP.js中:
<CommentList comments={this.state.comments} onDeleteComment={this.state.comments.deleteComment}/>
deleteComment(index) { let newComments = this.state.comments newComments.splice(index, 1) this.setState({ comments: newComments }) }
这个删除按钮如何做呢?每次点击删除就会显示props undefined