```Hello Everyone I have this checkbox working for...
# react
d
Copy code
Hello Everyone I have this checkbox working for select all. But the individual ones don't click. How do I fix it?        


         Box {
            Checkbox {
                onChange = { _, checked ->
                    checkAll = checked

                    console.log(selectedChecksState.forEach { a -> console.log(a) })
                    +"You have selected $selectedChecksState"
                }
            }
            Typography {
                variant = TypographyVariant.button
                +"Select All?"
            }
        }
        Box {
            for (item in <http://Title.ET|Title.ET>) {
                Box {
                    Checkbox {
                        checked = checkAll

                        onChange = { _, checked ->
                            if (checked) {
                                selectedChecksState.add(item)
                            } else if (!checked && selectedChecksState.isNotEmpty())
                                selectedChecksState.remove(item)

                            console.log(selectedChecksState.forEach { a -> console.log(a) })
                            +"You have selected $selectedChecksState"
                        }
                    }
                    +"${item}"
                }
            }
        }
a
All of your Checkboxes are showing the same state
checkAll
. Looks like thats not the behavior you want. Try giving every Checkbox its own individual state
d
I tried but it's not working
they are interdependant of one another
a
what exactly did you try?
d
I tried checking in the for loop if checked is true
I tried creating an additional state
I don't understand why I can't have onClick instead of onChange
why does that checkbox run if I don't click it
The for loop creates a checkbox for each string
Can you provide an example please
a
I am currently tied in something else, shifting focus to help you debug your code will derail me at the moment
d
ok no problem. If you can provide any direction or guidance I'll greatly appreciate it.
Thanks again.