luqin / react-icheck

:radio_button: iCheck components built with React. Highly customizable checkbox, radio buttons and radio group.
https://luqin.github.io/react-icheck
177 stars 40 forks source link

Warning on setting of checked property #20

Closed leojh closed 8 years ago

leojh commented 8 years ago

Getting the following warning when only setting the checked property:

warning.js?8a56:44 Warning: Input elements must be either controlled or uncontrolled (specify either the checked prop, or the defaultChecked prop, but not both). Decide between using a controlled or uncontrolled input element and remove one of these props.
luqin commented 8 years ago

Warning: Input elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled input element and remove one of these props. More info: https://fb.me/react-controlled-components

janpieterz commented 8 years ago

I'm encountering this as well after upgrading to 0.3.0. Reverted for now. 100% sure I'm not setting both checked and defaultChecked.

janpieterz commented 8 years ago

The fix doesn't look too difficult. Just removing the following line already made it work fine (defaultChecked is always set as a defaultProp so as soon as someone defines the checked property it has both on the rendered component).

I'm not 100% what other areas could be touched by this (I only use the Checkbox) so I didn't make a pull-request.

https://github.com/luqin/react-icheck/blob/master/src/EnhancedSwitch.js#L111

leojh commented 8 years ago

Exactly what @janpieterz is saying. I am also not setting both properties, just checked

luqin commented 8 years ago

Thank for your advice and PR. :+1: 0.3.1 has been released.