Having difficulty creating a controlled component with <Input type="checkbox"/>
See original GitHub issueDescription
—Having difficulty creating a controlled component with —
Other input types are able to be set as controlled component when provided the prop of value though.
Also unable to do have a controlled component with with the prop of defaultValue
Steps to Reproduce
-
Render a within a react Component
-
Force a setState change to toggle boolean value on the parent components of the <Input type="checkbox/>
3.) Repeat but with defaultValue = {this.state.checked}
Code that would not update after redux store simulated a form reset, which handled all other input
type but the checkbox.
checked={isChecked}
defaultValue={isChecked}
type="checkbox"
label={option}
size={this.props.size || 12}
key={index}
onChange={e => {
this.props.handleInput(
this.props.property,
this.props.type,
option
);
}}
EXPECTED: controlled component with
ACTUAL: Not controlled.
"react-materialize": "2.1.2",
materialize-css: 0.98.0 **react:**16.2.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
React a component is changing an uncontrolled input of type ...
Input elements should not switch from uncontrolled to controlled (or vice versa)." However my checbox is change via the state property.
Read more >Controlled checkbox seems not work correctly. #97 - GitHub
Hi, I made a controlled checkbox demo (by modify several lines of ControlledInput.purs) as follow : checkBox :: Props -> JSX checkBox =...
Read more ><input type="checkbox"> - HTML: HyperText Markup Language
Generally this is a square but it may have rounded corners. A checkbox allows you to select single values for submission in a...
Read more >Building a custom checkbox in React - LogRocket Blog
However, in React, the checkbox must either be a controlled or uncontrolled input. A controlled input allows us to take the responsibility away ......
Read more >Building a Checkbox Component with React and styled ...
Native checkboxes are notoriously difficult to style. Customization is tough because you cannot apply styles directly to the default ...
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 think I’m hitting this issue as well.
I have an element that can be toggled on/off via the checkbox. This is recorded in state as well. This works fine.
However, there are occasions when the element is toggled via a different source, and while the state changes appropriately, and even the
checked='true|false'changes in the underlying markup viewed in the dev tools, the actual checkbox on screen makes no change.Is this the same issue, and does anyone know of a workaround?
Please try
react-materialize3.xand reopen if this is still happening, thanks!