3 ms·
If it's a class based component (ES6), it could inherit from the other. But you could also extract the code logic in a product module, and reuse it in both com
by coldtea 11y ago
If it's a class based component (ES6), it could inherit from the other.
But you could also extract the code logic in a product module, and reuse it in both components, which can even be pure functions.
- oinksoft 11y agoThis is not limited to ES6+, class/inherits/super are syntactic sugar for existing prototypical OOP idioms.
- coldtea 11y agoIt's not limited to ES6, but it's not needed with the ES5 way of declaring React components, as mixins are supported there.
- oinksoft 11y agoActually you don't need to use React.createClass to use mixins, there is https://www.npmjs.com/package/react-mixin https://www.npmjs.com/package/react-mixin which implements them via decorators. Either I wouldn't consider inheritance and mixins interchangeable.