question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Having difficulty creating a controlled component with <Input type="checkbox"/>

See original GitHub issue

Description

—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

  1. Render a within a react Component

  2. 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
JacksonBatescommented, Aug 14, 2018

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?

0reactions
alextrasterocommented, Mar 24, 2019

Please try react-materialize3.x and reopen if this is still happening, thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found