I get this warning from reactJS.NET
bind(): You are binding a component method to the component. React does this for you automatically in a high-performance way, so you can safely remove this call. See LikeCon
Component looks like this
var LikeCon = React.createClass({
handleClick: function() {
var data = new FormData();
var like = !this.state.like;
var likeCounter = this.state.likeCount;
data.append("catgoryType", this.state.categoryKey);
data.append("objectId", this.state.objectId);
data.append("like", like);
if(like)
likeCounter++;
else
likeCounter--;
this.setState({ like: like, likeCount: likeCounter, userId: this.state.userId, categoryKey: this.state.categoryKey, objectId: this.state.objectId});
var xhr = new XMLHttpRequest();
xhr.open("post", "http://localhost:2215/Home/SetLike", true);
xhr.onload = function() {
};
xhr.send(data);
},
getInitialState: function() {
return { like: this.props.initialLike, likeCount: this.props.initialLikeCount, userId: this.props.userId, categoryKey: this.props.categoryKey, objectId: this.props.objectId };
},
render(){
return this.renderLikeButton()
},
renderLikeButton(){
return (
content =
<div className="likeCon">
<div className={this.state.like==true ? "likeButConAct" : "likeButCon"}>
<div className="likeB" title={this.state.like==true ? "Unlike" : "Like"} onClick={this.handleClick.bind(this)} >
</div>
{ this.state.likeCount > 0 ? <div className="likeCount">{this.state.likeCount}</div>: null}
</div>
</div>
);
}
})
I uses a bind when calling the method handleClick, If I remove this I will get another exception? So what am I supose to do?
this.handleClick.bind(this)
. React automatically binds to the component instance, so justthis.handleClick
is needed. The actual error seems more like you've forgotten to include the classFormData
. – MeningesFormData
should be in IE10 and higher ... assuming that the web page is being displayed in IE10 or higher mode (or Chrome or Firefox). There also should be no difference between thebind(this)
and without. They should be functionally identical. Have you tried to debug the flow with a breakpoint? – Meninges