This is perfectly normal, this is just basic inheritance. The danger of using inheritance to replace mixins is that there is no multiple inheritance, so you cannot pass your TextBox functions from multiple base classes, as if you were giving it several mixins. To get around this, you can use component composition . In your case, the composition will not work directly, as you defined in the example, but there is a workaround to this.
First you need to define a composite component
export default (ComposedComponent) => { class MyComponent extends React.Component { constructor(props, state) { super(props, state); this.state = { val: '' }; } bindTwoWay(name) { return { value: this.state[name], requestChange: (value) => { this.setState({[name]: value}) } }; } render() { return ( <ComposedComponent {...this.props} {...this.state} bindTwoWay={this.bindTwoWay.bind(this)} /> } } } return MyComponent }
And then you define your component where you need some common functions.
import compose from 'path-to-composer'; class TextBox extends React.Component { render() { return ( <div> <input valueLink={this.props.bindTwoWay('val')}/> <div>You typed: {this.props.val}</div> </div> ) } } export default compose(TextBox)
I have not tested this, but it should work.
source share