Skip to content

Instantly share code, notes, and snippets.

@license2e
Last active December 27, 2015 04:03
Show Gist options
  • Save license2e/105088798ce7ff9fa7d1 to your computer and use it in GitHub Desktop.
Save license2e/105088798ce7ff9fa7d1 to your computer and use it in GitHub Desktop.
ES6 Mixins
import Mixin from './utils/mixin'; // see below
import Mixin1 from './mixins/mixin1';
class App extends Mixin(React.Component, Mixin1) { // and so on: , Mixin2, Mixin3
componentDidMount() {
// this.someFuncFromMixin1()
}
render () {
return (
<div>
<h1>Hello world!</h1>
</div>
)
}
}
// source: https://gist.github.com/badsyntax/b2d9c843236960f145e7
// or another possible way is this way: http://es6-features.org/#ClassInheritanceFromExpressions (but seems more complex)
export default (Parent, ...mixins) => {
class Mixed extends Parent {}
Object.assign(Mixed.prototype, ...mixins);
return Mixed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment