0

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.

Xwingoga06
  • 99
  • 1
  • 10
  • You should definitely do some debugging to narrow down the specific operation which isn't doing what you expect. But I strongly suspect you're at least running into this: [The useState set method is not reflecting a change immediately](https://stackoverflow.com/q/54069253/328193) – David Nov 08 '22 at 13:51

0 Answers0