-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
Translate this react code into a simple example:
handleCategoryCheck(changeEvent){
var category = changeEvent.target.value
console.log("CHECK CATEGORY:", category)
var userCategories = this.state.userCategories
var categoryIndex = userCategories.indexOf(category) // will be -1 if item not in array
if (categoryIndex >= 0 ) {
userCategories.splice(categoryIndex, 1) // remove 1 item from array at the given position
} else {
userCategories.push(category)
}
console.log("CATEGORIES:", userCategories)
this.setState({userCategories: userCategories}) // this is updating state but why not triggering a re-render?
}Metadata
Metadata
Assignees
Labels
No labels