score:0

Accepted answer

you are mutating your state. this is a mutation:

data[choice.uuid].checked = false;

you shouldn't mutate your state, you should provide a new state and set it with your state setter function. this is why you have a setdata there.

function handlecheckbox(choice) {
  setdata((prev) => ({
    ...prev,
    [choice.uid]: {
      checked: !prev[choice.uid].checked,
    },
  }));
}

score:0

const handlecheckbox = (choice:ichoice) =>{
        setdata((prev) => ({
            ...prev,
            [choice.uuid]: {
                checked: !prev[choice.uuid].checked,
            }
        } as record<string,icheckbox>));
      }

is the correct way, thx devserkan


Related Query

More Query from same tag