I'm building a web app with react js. I have CSS set to that when a user selects a div it highlights and when clicked again, it deselects. This is the code I have in jquery (but it needs to be written in react).
$("#select-reward-cards .card").click(function () {
$(this).toggleClass('selected');
selectRewardsArray.push($(this).attr('data-value'));
});
$('.goal').click(function () {
$(".goal").removeClass("selected");
$(this).toggleClass('selected');
});
$("#reward-cards .card").click(function () {
if ($(this).hasClass('selected')) {
} else {
$("#reward-cards .card").removeClass("selected");
$(this).toggleClass('selected');
}
});
My react code is as follows:
var Test = React.createClass({
btnTapped: function(value, thisObj) {
console.log(value);
},
render: function() {
var stationComponents = this.props.stations.map((station, index) => {
return <div onClick={() => this. handleSort(station, $(this))}><img src="img/test.png" />{station}</div>;
});
return <div>{stationComponents}</div>;
}
});
var cards = ["amazon", "aeo", "aerie", "barnes", "bloomingdales", "bbw","bestbuy", "regal", "cvs", "ebay", "gyft", "itunes", "jcp", "panera", "staples", "walmart", "target", "sephora", "walgreens", "starbucks"];
ReactDOM.render(<Test stations={cards} />, document.getElementById('test-div'));
Please excuse my ignorance as I'm quite new to react, but how can I replicate the jquery functionality in react? Thanks.