I'm attempting to create an "upvote/downvote" thumbs up and thumbs down similar to the Reddit upvote and downvote system.
I want to be able to change the state/color of the object to green if thumbs up is clicked or red if thumbs down is clicked.
BUT, I don't want the user to be able to click thumbs up twice and go from green to default white... Any ideas?
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {counter: 0}
}
increment = (e) => {
e.preventDefault();
this.setState({
counter: this.state.counter + 1
});
}
decrement = (e) => {
e.preventDefault();
this.setState({
counter: this.state.counter - 1
});
}
render() {
return (
<div className="voting">
{this.state.counter}
<button className="upvoteBtn" type="submit" onClick={this.increment}>
<i className="fa fa-thumbs-up ml-2 mr-2"/>
</button>
<button className="downvoteBtn" type="submit" onClick={this.decrement}>
<i className="fa fa-thumbs-down ml-2 mr-2"/>
</button>
</div>
)
}
}