Created
August 7, 2015 07:16
-
-
Save StevenLangbroek/6f9df96ca5c6ac76f1e7 to your computer and use it in GitHub Desktop.
Difference between mixins and higher-order components (as ES7 decorators).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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