I have this code that inserts the ids of the checkboks into an array, but if I disable them, it does not remove them, i use update to react-addons-update any suggestions
constructor(props) {
super(props);
this.state={
keyGen:[]
}
}
render(){
<form>
{this.renderElements()}
<input type="submit" value="Save" />
</form>
renderElement(){
return this.props.Elements.map((item, index)=>{
render(
<Input name='list' type='checkbox' onClick={()=>this.updateStateList(item.id)} label='Add' className='listTour' />
)
})
}
updateStateList(value){
this.setState(update(this.state, {keyGen: {$push:[value]}}))
console.log(this.state.keyGen)
}
thanks
array.filter()in the updateStateList method to return the array without the Id. First you check if the Id that was just clicked is present in the array viaarray.some(). If it is present, usearray.filter()to filter the array out and setkeyGenequal to the filtered array.