5

I have a boolean array in useState

const [checkBoxState, setcheckBoxState] = useState([true,true,true,true,true,......]

I need a function that toggle only specific index value A function like this

const HanldeCheck = (index) => {
    setcheckBoxState[index] = !checkBoxState[index];
  };

Please Help

1 Answers1

12

maybe you can use something like this?

const HanldeCheck = (index) => {
    setcheckBoxState(prevState => prevState.map((item, idx) => idx === index ? !item : item))
};
Hovakimyan
  • 510
  • 3
  • 10