jeudi 13 octobre 2022

Children checkbox not selected on Parent checkbox selection in React

In a React project, certain records which are fetched from JSON are displayed. It also has checkbox, with Parent checkbox on the table head. My intention is when Parent checkbox is selected all children checkbox should be selected. I have also referred other posts but, none had been useful.So I tried with one solution but, didn't work. Please refer to code below.

const [checkedAll, setCheckedAll] = useState(false);

  // Function for Parent checkbox
  const selectAllCallback = (checked) => {
    setCheckedAll(true);
  };

  // Function for Children checkbox
  const checkBoxSelect = (checked, id) => {
    if (checkedAll) {
      checked = true;
    }
  };

This is what I am trying to implement. What could be the best solution to tackle this?. Please refer to codesandbox link --> https://codesandbox.io/s/jovial-aryabhata-95o2sy?file=/src/Table.js




Aucun commentaire:

Enregistrer un commentaire