Comment by jakelazaroff
5 years ago
Is it surprising that two-way data binding is a source of bugs? We learned that lesson from Angular, and it influenced React’s preference for one-way dataflow.
5 years ago
Is it surprising that two-way data binding is a source of bugs? We learned that lesson from Angular, and it influenced React’s preference for one-way dataflow.
2-way data binding is still a useful pattern with discipline, and still also common in React (using event handlers).
Any error-prone pattern can remain useful with enough discipline, but we've learned time and time again that relying solely on discipline to cover for error-prone patterns doesn't scale.
Define "we". :) I understand this sentiment though, and I also understand designing a flexible system with zero footguns is nigh impossible. My point however was that two-way databinding is not rare in React, and there are other potential footguns to be had in idiomatic React anyway (hooks, React Context).
2 replies →
It's never two-way in react. You're always in charge of updating the state in the event handler, which means you know where the update came from
Not to argue semantics, but that pattern is still called two-way databinding in my neck of the woods. In this deprecated page from the official docs, two-way databinding is defined as:
> Two-way binding — implicitly enforcing that some value in the DOM is always consistent with some React state — is concise and supports a wide variety of applications.
[1] https://reactjs.org/docs/two-way-binding-helpers.html
2 replies →
What do you mean by two-way and one-way exactly? (Asking it because web sometimes has a different history for terms.)