score:7

Accepted answer

issue is with this line:

{this.props.postcomments.map( this.rendercomment )}

because you forgot to bind rendercomment, map callback method, so this inside rendercomment method will not refer to the class context.

use any one of these solutions, it will work.

1- use this line in constructor:

this.rendercomment = this.rendercomment.bind(this) ;

2- pass this with with map like:

{this.props.postcomments.map(this.rendercomment, this)}

3- use arrow function with rendercomment method, like this:

rendercomment = (comment, i) => {
    .....

or use the map inside the rendercomment function (i used to prefer this way), like this:

rendercomment() {
    return this.props.postcomments.map((comment, i) => {
        return(
            <div classname="comment" key={i}>
                <p>
                    <strong>{comment.user}</strong>
                    {comment.text}
                    <button 
                        onclick={this.handleremovecomment}
                        classname="remove-comment">
                        &times;
                    </button>
                </p>
            </div>
        )
    })
}

and call this method from render, in this case binding of rendercomment is not required:

{this.rendercomment()}

Related Query

More Query from same tag