Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How are bindings in React not two-way? Update an input field and it updates the underlying JS object. Update the object and it updates the input field. I thought that was the definition of two-way, regardless of what happens behind the scenes.


It doesn't update the underlying object for you by default.

If you use an uncontrolled component (by giving it a defaultValue/defaultChecked prop) you have to pick up the new value using an event or directly via the DOM. If you do it this way, you can't update the displayed value by changing the props passed to it.

If you use a controlled component (by giving it a value/checked prop), its displayed value won't update unless you pick up the new value from an event and set it in whichever JS object you have holding its state for the next render. There's a helper for doing that, or it's easy enough to roll your own event handler which takes care of all your fields.

http://facebook.github.io/react/docs/forms.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: