You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some React components have onHide/onChange/other functions which store the functions to the DOM (beyond our control, library components). Thus if we pass it something like:
the function bound to the onHide can get out of sync with the state (it saved a reference to the old Link object to the DOM on first creation instead of re-rendering it).
The workaround for this is to do something like
class SomeComponent extends React.Component {
boundFunction() {
const { someLink } = this.props;
someLink.set(false); // Some Value
}
render() {
return <Modal onHide={this.boundFunction} />
}
}
It would be nice to have a convenience function on LinkedComponent which can "generate this boundFunction for you". Maybe the usage interface would be something like:
class SomeComponent extends LinkedComponent {
//Implicitly from LinkedComponent
bindLink(somePropString, callback) {
const propLink = this.props[somePropString];
//Or some other way to make it more generalized?
link.update(callback);
}
render() {
const { someLink } = this.props;
return <Modal onHide={this.bindLink(somePropString, () => {})} />
}
}
The text was updated successfully, but these errors were encountered:
richard-engineering
changed the title
Convenience onX method binding pattern for Link.Component classes
Enhancement: Convenience onX method binding pattern for Link.Component classes
Jul 13, 2017
Some React components have onHide/onChange/other functions which store the functions to the DOM (beyond our control, library components). Thus if we pass it something like:
the function bound to the onHide can get out of sync with the state (it saved a reference to the old Link object to the DOM on first creation instead of re-rendering it).
The workaround for this is to do something like
It would be nice to have a convenience function on LinkedComponent which can "generate this boundFunction for you". Maybe the usage interface would be something like:
The text was updated successfully, but these errors were encountered: