I'm trying to reproduce a simple two-way binding example in the React.js framework by following this official tutorial: "Two-Way Binding Helpers".
I created a "MyCheckbox" component that looks like this:
var MyCheckbox = React.createClass({
mixins: [React.addons.LinkedStateMixin],
getInitialState: function () {
return {
fieldname: '',
value: this.props.value
};
},
render: function () {
var valueLink = this.linkState('value');
var me = this;
var handleChange = function (e) {
valueLink.requestChange(e.target.value === 'on');
};
return React.DOM.input({
type: 'checkbox',
checked: valueLink.value,
onChange: handleChange,
});
}
});
"MyCheckbox" is rendered the following way:
React.renderComponent(MyCheckbox({
value: false
}), document.body);
When rendering the first time, everything works as expected, if the value is true, the checkbox will be checked, if the value is false then it will not.
If you initialise the checkbox as being unchecked and then check it, everything works fine.
The issues it that when clicking the checkbox to uncheck it,
e.target.valueis always 'on'.I also wanted to ask what differences are there between the ReactLink Without LinkedStateMixin and ReactLink Without valueLink methods of data-binding ?
Any ideas ?
I use the latest React.js version (v0.10.0).