Can't for the life of me figure this out. Every time setState() is called, the component is supposed to re-render, right? I have a series of print statements set up, and so I can see that my handler is being fired but render() is not. Please help me understand what is going wrong here!
Here are the important parts of my code:
My constructor:
constructor(){
super();
this.state = {upvoted:false}
this.handleFavorite = this.handleFavorite.bind(this);
}
My handler:
handleFavorite(event){
event.preventDefault();
console.log("handleFavorite fired");
var query=location.pathname;
query = query.split('/');
var username1=query[2];
var playlist=query[3];
var vote = this.props.data.vote;
var self = this;
if (username1) {
request
.post('/api/endpoint')
.end(function(err, res) {
self.setState({upVoted: true});
self.forceUpdate();
console.log("status "+res.body.status);
});
}
}
My handler call:
render() {
return (
<div onClick={this.handleFavorite}>stuff</div>
);
}