I'm struggling with checking off all checkboxes at once within a table. I can check of individual checkboxes, however I also want the option to check off one "master checkbox", which checks all the other ones off.
I've created a simplyfied version of my React component: https://codesandbox.io/s/lively-wildflower-fknn9
There are two things with this I'm struggling with.
If we remove the checked attribute on each of the two checkboxes, we can manually check each one and get it printed out to console. If we override the checked parameter by setting it to
checked={checkAll}we can click the All checkbox, and both checkbox 1 and two gets checked off. However, it does not invoke theonChangeattribute of the checkbox, which means I'm not able to record the checks.If I put on the
checked={checkAll}attribute, I'm basically overriding the checkbox, which means the checkbox icon itself won't change from checked to unchecked. TheonChangeattribute is however invoked, and I'm able to record the change to the console.
I would like to check both checkboxes individually, and also use the "master checkbox" to check off both checkboxes, and invoke their onChange at the same time.
How can I go about doing this? Any suggestions would be super helpful
