I created a function that toggles the active state of list items when clicked:
React
toggleActive: function(item){
item.active = !item.active;
},
JSX
<li key={property.id} onClick={() => this.toggleActive(property)}>
Is there a way to count the number of items that are active later on? I would like to store this count in a variable.
I initially attempted something like this:
var count = this.properties.filter(item => item.active).length;
However, I am having trouble getting it to work as expected.