I'm just learning React and I am writing components using ES7 syntax. My idea is to create a base component which will contain some methods that I want all derived components to have. For example, I want to implement valueLink without the mixin, for two-way binding in all my components. Here is my idea:
class MyComponent extends React.Component {
bindTwoWay(name) {
return {
value: this.state[name],
requestChange: (value) => {
this.setState({[name]: value})
}
}
};
}
class TextBox extends MyComponent {
state = {
val: ''
};
render() {
return (<div>
<input valueLink={this.bindTwoWay('val')}/>
<div>You typed: {this.state.val}</div>
</div>)
}
}
And it works just fine. However, I wasn't able to find much information about this method. It's not about valueLink, that was just an example. The idea is to have some methods in a base component and later extend that component so that derived components have all those methods, like the usual OOP way. So I would just like to know if this is perfectly fine or there are some flaws that I am not aware of. Thanks.