I am building a simple password generator where the user clicks on a ‘submit’ button and is displayed a password based on which input checkboxes are ticked.
I currently have 4 pieces of state for each checkbox, and a simple input file that returns a simple input with a checkbox. I call this input file with each of their state as a prop as well as an event handler that they all use.
So i am currently stuck on how to see which input checkboxes are ticked and which are not… when i try to see this it is either they are all ticked, or they are all false (even when checkbox 1 and 2 are false and checkbox 3 and 4 are true).
I am a bit confused as to why this isnt working… any help?
Please let me know if you want me to provide some code to help better understand
2
Answers
You can keep your state in an object, and update its values on change like:
Just store the 4 checkboxes in an object like below
and now wrtite an onChange function for handling clicks :
};
u can log the option state to see which checkboxes are checked. 🙂
u can visit this link for more :
https://dev.to/collegewap/how-to-work-with-checkboxes-in-react-44bc
or look at this live demo.