Drop ReactLink hooks in controlled components
sebmarkbage opened this issue · 10 comments
ReactLink supports a sort of adhoc two-way data binding. We've found it to be a distraction rather than helpful so we don't plan on adding it to the core outside of addons anyway.
We should take the support out of controlled components and make wrappers that can be used instead of the controlled components, and put the wrappers in addons. This provides backwards compatibility without having the legacy remain in core.
👍
This should be rather trivial, should I draft a PR?
@sebmarkbage Could you give examples of wrappers needed ? (I'm new to the contribution in React, sorry if I ask trivial questions ^^')
Any clues ?
@sebmarkbage Could you give an example of how to best deal with multiple form inputs without linkState?
The two following are equivalent, it's just sugar really.
<input valueLink={vl} />
<input value={vl.value} onChange={vl.requestChange} />
https://github.com/facebook/react/blob/master/src/addons/link/LinkedStateMixin.js
https://github.com/facebook/react/blob/master/src/addons/link/ReactLink.js
ReactLink may be "just sugar really," but when you have dozens of inputs in a form and hundreds in the entire application, it makes a noticeable difference. JSX itself is "just sugar really," but it's an important tool for productivity and readability.
Compare:
<input valueLink={this.linkState("surname")} />
<input value={this.linkState("surname").value} onChange={this.linkState("surname").requestChange} />
That being said, I'm all for taking ReactLink out of core, _if_ the syntax doesn't explode like in the example above.
@tobia Like I mention in #3591, you can wrap an input
in your own component of your own which can provide the same functionality (and more). If/when it's dropped React would certainly provide such wrappers out-of-the-box in addons, but it wouldn't really be special or anything you can't already do yourself.