How can I dynamically set the name of the array in state, to get it from state.
onCheckBoxItemClickList(e, value, path) {
console.log(e.target.checked)
if (e.target.checked) {
//append to array
this.setState({
[path]: this.state.[path].concat([value])
})
} else {
//remove from array
this.setState({
[path]: this.state.[path].filter(function (val) {
return val !== value
})
})
}
}
I know how to dynamically set and get a key in state, but when I try and do
[path]: this.state.[path].concat([value])
I get the below error:
Any help would be greatly appreciated, Thanks