Skip to content

Instantly share code, notes, and snippets.

@developit
Created January 27, 2016 01:52
Personally I see the value of both. Depends on the codebase.
// mixins with createClass:
const Foo = createClass({
...someMixin,
render: ({ onClick, children }) => (
<div class="foo">
<button onClick={onClick}>Click Me</button>
{ children }
</div>
)
});
// mixins with class sugar + decorator (see below):
@mixes(someMixin)
class Foo extends Component {
render({ onClick, children }) {
return (
<div class="foo">
<button onClick={onClick}>Click Me</button>
{ children }
</div>
);
}
}
// Here's a simple decorator that satisfies the above usecase:
function mixes(...behaviors) {
return target => behaviors.forEach( b => Object.assign(target.prototype, b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment