Working with checkboxes always produces warning in console
See original GitHub issueTo reproduce the problem add something like this in a kotlin-react app. The state needs to have a var myBoolean, that has an initial value of false:
input(InputType.checkBox) {
attrs.onChangeFunction = { event ->
val newValue = (event.target as HTMLInputElement).checked
setState { myBoolean=newValue }
}
attrs.checked = state.myBoolean
}
Then open the app in the browser and click on the checkbox. The following warning will appear in the console of the browser: “A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.”
I have investigated the issue myself and I suspect that the problem is due to the setter of the checked property of the input removing the checked attribute when the value is false.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Checkboxes in ReactJS - Stack Overflow
I found this question but it has a ton of upvoted answers where everyone is doing something else. Some answers use checked={isCheckedState} , ......
Read more >How to work with checkboxes in React - DEV Community
Now if you try to check the checkbox, nothing would happen and you will see the following warning in the console:.
Read more ><input type="checkbox"> - HTML: HyperText Markup Language
Checkboxes do support validation (offered to all <input> s). However, most of the ValidityState s will always be false . If the checkbox...
Read more >Check if a Checkbox is checked in React | bobbyhadz
Use the `target.checked` property on the `event` object to check if a checkbox is checked in React, e.g. `if (event.target.checked) {}`.
Read more >Checkbox not working - Inertia with ReactJS - Laracasts
I have a form in a modal that creates a user with roles. When I try to check the roles and output the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also ran into this.
Workaround:
@Hypnosphi Sadly, as three developers in a startup we don’t have resources for that kind of thing.