Banshee Banshee -4 years ago 170
Javascript Question

bind(): You are binding a component method to the component. React does this for you automatically?

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 = !;
var likeCounter = this.state.likeCount;

data.append("catgoryType", this.state.categoryKey);
data.append("objectId", this.state.objectId);
data.append("like", like);


this.setState({ like: like, likeCount: likeCounter, userId: this.state.userId, categoryKey: this.state.categoryKey, objectId: this.state.objectId});

var xhr = new XMLHttpRequest();"post", "http://localhost:2215/Home/SetLike", true);
xhr.onload = function() {
getInitialState: function() {
return { like: this.props.initialLike, likeCount: this.props.initialLikeCount, userId: this.props.userId, categoryKey: this.props.categoryKey, objectId: this.props.objectId };
return this.renderLikeButton()
return (
content =
<div className="likeCon">
<div className={ ? "likeButConAct" : "likeButCon"}>
<div className="likeB" title={ ? "Unlike" : "Like"} onClick={this.handleClick.bind(this)} >
{ this.state.likeCount > 0 ? <div className="likeCount">{this.state.likeCount}</div>: null}


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?

Answer Source

Pass *.bind(null,this) instead;

See this Google Groups thread for explanation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download