Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Created August 7, 2015 07:16
Show Gist options
  • Save StevenLangbroek/6f9df96ca5c6ac76f1e7 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/6f9df96ca5c6ac76f1e7 to your computer and use it in GitHub Desktop.
Difference between mixins and higher-order components (as ES7 decorators).
import React from 'react';
function animateIn(Component){
return class DecoratedComponent extends React.Component {
componentWillEnter(){
// Do some swanky animation
}
render(){
// Inherit all props
return <Component {...this.props} />;
}
}
}
@animateIn
class MyComponent extends React.Component {
render(){
return <h1>Hello world!</h1>;
}
}
var React = require('react');
var AnimateIn = require('../mixins/AnimateIn');
var MyComponent = React.createClass({
mixins: [AnimateIn],
render: function(){
<h1>Hello world!</h1>
}
});
module.exports = MyComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment