addCheckboxToSelectedArray = (item, hash) => {
return new Promise((res, rej) => {
try{
let checkboxes = this.state.selectedCheckboxes;
if(checkboxes.some(e => e.value === item)){
const findIndexOf = function(arr, val){
for(let i = 0; i < arr.length; i++) {
if(arr[i]['value'] === val){
return i;
}
}
};
let indexOf = findIndexOf(checkboxes, item);
checkboxes.splice(indexOf, 1);
this.setState({
selectedCheckboxes: checkboxes
})
} else {
this.setState({
selectedCheckboxes: checkboxes.concat({value: item, hashKey: hash})
})
}
res(item);
}
catch(e){
rej(e);
}
})
}
Created
October 3, 2018 13:55
-
-
Save andrit/c8e30f32403c38c2518f4a1f7fe949e1 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment