Skip to content Skip to sidebar Skip to footer

Delete A Comment - React Js

Actually, I've been trying to add a 'Delete a comment' functionality to my Comment Box system. Here is my code:- var Comment = React.createClass({ handleClick: function(e){

Solution 1:

The function passed to map will not automatically share a this pointer with your react class.

To use this inside the anonymous function, call .bind(this) at the end of the function definition to yield a function with the expected this inside.

var commentNodes = this.props.comments.map(function (comment, index) {
    ...
});

Becomes:

var commentNodes = this.props.comments.map(function (comment, index) {
    ...
}.bind(this));

Post a Comment for "Delete A Comment - React Js"