I have a lot of different checkbox with different array to filled.
here is my checkbox (i have 4 différents) "required_licence":[] "equipment":[] ...
<Checkbox
style={styles.checkbox}
value={props.box.cotier}
onValueChange={() => {
props.checked(
"cotier", ** My value to record inside my array **
"required_licence", ** the name of my array **
"box", ** the type of my values (because i also have input) **
props.isChecked ** to change if i'm true or false **
);
}}
color={props.box.cotier ? "#4630EB" : undefined}
/>
Also my fonction to add the value inside my state "form"
const checked = (value, fieldName, type, checked) => {
setBox((oldValue) => {
return {
...oldValue,
[value]: !box[value],
};
});
let values = [value];
if (type === "box") {
if (box[value] === false) {
setArray((oldValue) => [...oldValue, value]);
} else {
let index = array.indexOf(value);
array.splice(index, 1);
}
}
setForm((oldValue) => {
return {
...oldValue,
[fieldName]: [value]
};
});
};
when i click on my checkbox, the value is inside my array but delete the other one so i always have just one value .
My else is supposed to delete when my box is not selected.